Recursive custom de-serialiser ? #149
ArthwitRail
started this conversation in
General
Replies: 1 comment 1 reply
-
Have you searched stackoverflow? That site has a much larger community and history of answers to questions. Eg https://stackoverflow.com/questions/23280785/jackson-deserializing-recursive-object |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a bit of a challenge with Jackson databind which means i need to implement customer de-serialisers for a class heirarchy. I get how do todo them and have proven with example code before i make a start on my complex json object.
By way of an example below i have an object with a field mydata, thats a list of MyDataItems (pojo) which have a datavalue (int) and children which are a list of MyDataItems (these can be null or even omitted). I have a MyDataItemDeserialiser which extends StdDeserializer.
However i am a bit stuck because the structure is recursive and when MyDataItemDeserialiser is called I (quite rightly from what i tell) get calls to it for the top level items in my json. Those being the ones with datavalues 23,33,44 and 55.
Whats best practice to go about recursively calling the deserialiser to construct the children lists of MyDataItems ?
{
"mydata" : [
{
"datavalue" : 23,
"children" : null
},
{
"datavalue" : 33
},
{
"datavalue" : 44,
"children" : [
{
"datavalue": 101,
"children" : [
{
"datavalue" : 201,
"children" : null
},
{
"datavalue" : 202,
"children" : null
}
]
},
{
"datavalue": 102,
"children" : null
}
]
},
{
"datavalue" : 55
}
]
}
Beta Was this translation helpful? Give feedback.
All reactions