I process JSON from Java to Jackson, but I want to check the data before conversion.

Asked 2 years ago, Updated 2 years ago, 68 views

JSON was converted into an object using Jackson 2.7.3 version.

Question 1. I want to check the JSON value before converting JSON into an object, how do I do it?

Question 2. If number 1 is possible, NULL processing is possible. If it's impossible, there's an error when there's no data when converting to an object, how should I handle it?

json java spring

2022-09-22 21:53

1 Answers

Q1.

You can catch it with Json Processing Exception

ObjectMapper objectMapper = new ObjectMapper();
try {
    JsonNode jsonNode = objectMapper.readTree(json);
    ///...
} } catch (JsonProcessingException e) {
    e.printStackTrace();
    ///...

} } catch (IOException e) {
    e.printStackTrace();
    ///...
}


2022-09-22 21:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.