I'm pretty new to using Jackson and I'm trying to follow my team's patterns for deserializing our JSON. Right now I am running into an issue when a field name doesn't match the JSON property.
Working example:
@JsonDeserialize(builder = ProfilePrimaryData.Builder.class)
@Value
@ParametersAreNonnullByDefault
@Builder(builderClassName = "Builder")
private static class ProfilePrimaryData {
private final Boolean hasProfile;
@JsonPOJOBuilder(withPrefix = "")
public static class Builder {
}
}
If the JSON property is hasProfile, it works fine, but if it's has_profile (which is what our client is writing), it doesn't work and I get an error: Unrecognized field "has_profile" (class com.mypackagehere.something.$ProfilePrimaryData$Builder), not marked as ignorable (one known property: "hasProfile"])
. I've tried adding a JsonProperty annotation to hasProfile like this but it still doesn't work:
@JsonDeserialize(builder = ProfilePrimaryData.Builder.class)
@Value
@ParametersAreNonnullByDefault
@Builder(builderClassName = "Builder")
private static class ProfilePrimaryData {
@JsonProperty("has_profile")
private final Boolean hasProfile;
@JsonPOJOBuilder(withPrefix = "")
public static class Builder {
}
}
Am I misunderstanding how this is supposed to work?