I am trying to parse json file using jackson @JsonProperty. I have an interesting problem at hand. One of the field name that is marked as @JsonProperty can be different based on input source. Example json files below
car1.json --> {"car": {"color": "yellow","type": "luxurySedan"}}
car2.json --> {"car": {"color": "yellow","modeltype": "SUV"}}
My Datamodel is something like
@Data
class Car {
@JsonProperty("color")
private String color;
@JsonProperty("type")
private String type; // Don't want to use alias to solve above problem
}
Second file car2.json does not get parsed. I tried following on field type to get value from a property file (using spring boot) but it is not working as expected. I am reluctant to use alias
purely because I will have to change code if field name changes for any one of the file. Can someone help please
@JsonProperty(@Value("${car.type}")) // Compilation error (It's a spring boot project)
@JsonProperty("${car.type}") // Values not read