Here is a simple Object
@Builder
@Value
@JsonDeserialize(builder = User.UserBuilder.class)
class User {
@NotNull
@JsonProperty("user_name")
private final string userName;
@JsonPOJOBuilder(withPrefix = "")
public static final class UserBuilder {}
}
Now, if I want to use ObjectMapper
to read a string to this, I do
final User user = MAPPER.readValue("{\"user_name\":\"my-name\"}", User.class);
But this does not read the user_name
because when I look at the generated source code for the builder, I see
public static final class UserBuilder {
private String userName;
}
And so the camelCase doesn't match the snake_case. Normally if I were to manually generate the Builder class, I would put @JsonProperty("user_name")
on the builder property as well.
How do I fix this?