Skip to content
Advertisement

Jackson deserialize JSON into pojo with map property

Can somebody help me, how I can deserialize the following JSON, which I can not change? I am using Jackson for serialization.

JavaScript

Columns can have unknown number of headers and their value eg. “Header1” is used in the rows array.

So far I have the following structure:

JavaScript

The problem is that the Map is empty when I deserialize into QueryResult; I read about TypeReference but I do not know how I can specify a TypeReference<HashMap<String,CellValue>> for the property values in QueryResultRow.

Edit:

My ObjectMapper code is the following:

JavaScript

The content of queryResultString is the JSON above.

Advertisement

Answer

First problem is your JSON is invalid. I assume it should be something like this,

JavaScript

Then answer is quite straightforward. You need to change your QueryResultRow as follows,

JavaScript

Then I think you should good to go.

Here is a complete working example,

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement