klaxon icon indicating copy to clipboard operation
klaxon copied to clipboard

Parse json object with various field types

Open squallsama opened this issue 4 years ago • 0 comments

Right now I'm trying to use klaxon to parse following json structure:

{ "score": 50, "itemId": "111", "fields": { "itemType": "ONLINE", "skus": [ "11111", "22222" ], "attributes": { "category": [ "Featured Products/Flooring", "Flooring/Tile" ], "sizes": [ "s", "xl" ] } } }

I have data class for such structure: `data class Item(

    @Json(name = "itemId")
    val itemId: String? = null,

    @Json(name = "score")
    val score: Float,

    @Json(name = "fields")
    val fields: Map<String, Any>? = null

)`

And when I use klaxon val item: Item = klaxon.parse(itemJson)

All fields in my item object looks fine except "attributes" - they parsed as Object instead of Map<String, Map<String, Any>>.

Any suggestions how I can resolve this issue using Klaxon ?

squallsama avatar Aug 18 '20 18:08 squallsama