Skip to content
Advertisement

Deserialising JSON array using RestTemplate

I’m trying to convert JSON data to a java class using Rest Template.

The JSON data has this format and cannot be changed:

JavaScript

The java class to save the data is:

JavaScript
JavaScript

To receive the JSON data and deserialize i’m doing:

JavaScript

But i’m getting this exception:

JavaScript

I’ve done this before and it worked, but the JSON data had a slightly different format. But this time I cannot understand this error.

Advertisement

Answer

The annotation @JsonFormat(shape=JsonFormat.Shape.ARRAY) lets Jackson look for an array representation of a Vehicle class. That could look like this:

JavaScript

The order of the variables need to match the order of the class attributes. That’s what the Shape.ARRAY is doing.

What you probably want is the actual Object representation. Therefore just remove the @JsonFormat(shape=JsonFormat.Shape.ARRAY) and it will work.

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