0

I want to parse json value but there are some value without keys.

like this

"geometry": {
                "type": "LineString",
                "coordinates": [
                    [
                        127.08373748622218,
                        37.529508099979225
                    ],
                    [
                        127.08355138558433,
                        37.529735847943925
                    ]
                ]
            }

Geometry.class

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Geometry {
    private String type;
    private Coordinate coordinates;
}

Coordinate.class

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Coordinate {
    private List<Double[]> xy;
}

then i saw this error

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `kr.seoulmaas.ieye.service.dto.path.walk.Coordinate` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 133] (through reference chain: kr.seoulmaas.ieye.service.dto.path.WalkPathResDto["features"]->java.util.ArrayList[0]->kr.seoulmaas.ieye.service.dto.path.walk.Feature["geometry"]->kr.seoulmaas.ieye.service.dto.path.walk.Geometry["coordinates"])
2
  • Post a complete minimal example, with hardcoded JSON input, trying to deserialize this JSON input. Commented Jul 14, 2019 at 10:00
  • show the RestTemplate code Commented Jul 14, 2019 at 10:21

3 Answers 3

1

private Coordinate coordinates; should be private List<Coordinate> coordinates; since it is an array in the JSON, but since the array contains only arrays you need to have a list of lists: List<List<Double>> coordinates (suggested by @JBNizet).

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

1 Comment

It should actually be a List<List<Double>>, or a List<Double[]> directly. It' not an object, but it's also not an array of objects.
0

In your data, coordinates is a list of list. So define your Geometry class this way:

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Geometry {
    private String type;
    private List<Coordinate> coordinates;
}

Hope this helps.

Comments

0

Sorry, I'm dreadfully late.

I solved this problem using by JsonNode.

this is my code.

public class Geometry {
    private String type;
    private JsonNode coordinates;
}

2 Comments

But how did you solve it by using JsonArray? It may not be as clear to some as to how you did it. Please update your answer with more details, thanks!
Oh, Sorry i confused with JsonNode. I solve this problem with JsonNode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.