A memo that I was addicted to when receiving a response in json format from an external API and converting it to a model class.
I am converting json to a model with com.fasterxml.jackson.databind.ObjectMapper # readValue (String, TypeReference)
, but an exception occurs if there is an item in json that does not exist in the model field.
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
Add @JsonIgnoreProperties (ignoreUnknown = true)
to the model class.
@NoArgsConstructor
@JsonNaming(SnakeCaseStrategy.class)
@JsonAutoDetect(getterVisibility = Visibility.NONE)
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class hogehoge {
}
Like this.
Chan-chan.
Recommended Posts