0

I would like to ask you guys how to deserialize nested object with jackson. I got example Json File:

{ "id": "1", "comment": "Some comment", "user": "Smith", "date": "2018-05-31", "shape": "oval", "coordinates": [ ["50", "130"], ["370", "500"] ] }, 

Let's say that main Class is called Comment, but I would like to create another class Coordinates with local variables x1, x2, y1, y2. So class Comment looks like that:

 public class CommentFile implements Serializable{ private Long id; private String comment; private String user; private String date; private String shape; private Coordinates coordinates; //setters, getters, constructor 

But because in json i have 'array' "coordinates": [ ["50", "130"], ["370", "500"] ], i dont know how to convert this to:

public class Coordinates implements Serializable{ private double x1; private double y1; private double x2; private double y2; 

Any ideas?

1 Answer 1

1

A straightforward way is to use List<List<String>> coordinates; to deserialize the JSON to Java first. Later, you can implement a method something like getCoordinatesObject() inside CommentFile class to create and get a Coordinates object.

There might be a better way to accomplish this directly with Jackson but you can do this as well.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.