aeruhxi
02/12/2018, 8:23 AMcall.receive<SomeDataClass>()
parse json string?gildor
02/12/2018, 8:38 AMContentNegotiation
feature enabled with some Json mapping library (Gson and Jackson implementations are available as part of ktor but you should add them to dependencies)aeruhxi
02/12/2018, 8:45 AMinstall(ContentNegotiation) {
gson {
setDateFormat(DateFormat.LONG)
excludeFieldsWithoutExposeAnnotation()
}
}
Is this enough for that?gildor
02/12/2018, 8:49 AMaeruhxi
02/12/2018, 8:50 AMaeruhxi
02/12/2018, 8:51 AMdata class CreatePostRequest(
val content: String?,
val userId: Long,
val with: List<Long>?,
val checkedIn: Long?,
val foodId: Long?,
val menuCategoryId: Long?,
val actType: String?,
val photos:List<String> = emptyList()
)
which isn't being deserializedgildor
02/12/2018, 8:51 AMgildor
02/12/2018, 8:52 AMgildor
02/12/2018, 8:52 AMisn’t being deserializedWhat does it mean?
aeruhxi
02/12/2018, 8:52 AMaeruhxi
02/12/2018, 8:53 AMCreatePostRequest(content=null, userId=0, with=null, checkedIn=null, foodId=null, menuCategoryId=null, actType=null, photos=null)
gildor
02/12/2018, 8:53 AMapplication/json
, if requests have something like text/plain
ContentNegotiation doesn’t work for Gsongildor
02/12/2018, 8:53 AMaeruhxi
02/12/2018, 8:53 AMapplication/json
gildor
02/12/2018, 8:53 AMgildor
02/12/2018, 8:54 AMaeruhxi
02/12/2018, 8:54 AM{
"content": "ABCasdasdDFE",
"userId": 1,
"with": [
2,
3
],
"checkedIn": 2,
"menuCategoryId": 1,
"actType": "eat"
}
gildor
02/12/2018, 8:54 AM@Expose
annotation on your fieldsgildor
02/12/2018, 8:54 AMexcludeFieldsWithoutExposeAnnotation
?gildor
02/12/2018, 8:54 AMaeruhxi
02/12/2018, 8:55 AMaeruhxi
02/12/2018, 8:55 AMExpose
aeruhxi
02/12/2018, 8:56 AM@Expose
as I configured itgildor
02/12/2018, 8:56 AMaeruhxi
02/12/2018, 8:57 AMgildor
02/12/2018, 8:57 AM@field:Expose
val content: String?
aeruhxi
02/12/2018, 8:57 AMgildor
02/12/2018, 8:58 AMcontent
is property, so in bytecode it’s actually getter, setter and private field, so you should annotate field, because Gson know nothing about kotlin propertiesgildor
02/12/2018, 8:59 AMexcludeFieldsWithoutExposeAnnotation
for data classesaeruhxi
02/12/2018, 9:00 AMgildor
02/12/2018, 9:00 AMgildor
02/12/2018, 9:01 AMgildor
02/12/2018, 9:01 AMaeruhxi
02/12/2018, 9:02 AMgildor
02/12/2018, 9:03 AMaeruhxi
02/12/2018, 9:04 AMgildor
02/12/2018, 9:04 AM@field:Expose
you can use just @Expose
, because this annotation only targets fields, so everything should workgildor
02/12/2018, 9:04 AMaeruhxi
02/12/2018, 9:04 AM