0

Lets say you have JSON which are schema less and let's say you haved a class that looks like this:

public class Score {

    @JsonProperty("game-score")
    private int gameScore;

    @JsonProperty("high-score")
    private int highScore;

    // Getters & Setters
}

So, lets say that that JSON looks like this:

{ "game-score": 100, "high_score":16000 }

When marshalling this JSON using Jackson, I receive the following from my Overriden toString() method (in which I placed the '{' and '}' explicitly):

{"game-score":100, "high-score": 0}

As you can see that the problem is the real property (for highScore) set has a "-" and the JSON being marshalled has a "_".

This causes the property to go to its default value when one invokes a toString() method or invokes a getHighscore() method from the Score class.

Question(s):

(1) Given a class that has specific @JsonProperty set, is there a way to parse a JSON String to check if it matches the @JsonProperty inside the POJO before or after the marshalling process and then setting a return boolean method to false?

(2) How to get all JSON names and values from a populated JsonNode using Jackson?

Thank you for taking the time to read this...

PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144

0 Answers0