deserialization help - array

8 views
Skip to first unread message

Nicola Delbono

unread,
Jul 16, 2019, 9:17:52 PM7/16/19
to jackson-user

Hello, 
I can't figure out how to deserialize the following structure.


         "years":{  
            "2019":{ /* contains "week" objects */ },
            "2020":{ /* contains "week" objects */ },
            "2021":{ /* contains "week" objects */ }
         },


The mappers keeps saying 

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "2019"

It looks for properties named after the years which is obviously not possible.

I tried

public Map<String,Week> year;

and other variations but none worked.

Can someone point me to the right directions? (with an example maybe)
I'm stuck with this probably simple issue.

Thanks a lot in advance

Tatu Saloranta

unread,
Jul 18, 2019, 1:42:17 AM7/18/19
to jackson-user
That should work in some form, but I suspect you have some structural mismatch.
Assuming json is like:

{
"years":{
"2019":{ /* contains "week" objects */ }
}
}

then it would map to POJO

public class Stuff {
public Map<String, Week> years;
}

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages