Can I use MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX with ParameterNamesModule? #5289
-
Recently I read the cowtowncoder blog I thought that it would be possible to use static class Apple {
private final String iPhone;
public Apple(String iPhone) {
this.iPhone = iPhone;
}
public String getIPhone() {
return iPhone;
}
@Override
public String toString() {
return "Apple{" +
"iPhone='" + iPhone + '\'' +
'}';
}
}
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.enable(MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX)
.build();
Apple apple = new Apple("iPhone 15");
String json = mapper.writeValueAsString(apple);
System.out.println(json); // {"iPhone":"iPhone 15"}
Apple result = mapper.readValue(json, Apple.class); // Error thrown
System.out.println(result);
} It seems like the property name is determined by the constructor parameter and |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
There should be nothing preventing use of Thank you for reporting the problem! |
Beta Was this translation helpful? Give feedback.
-
Great! |
Beta Was this translation helpful? Give feedback.
-
Fixed for 2.20.1 (see #5292). |
Beta Was this translation helpful? Give feedback.
There should be nothing preventing use of
ParameterNamesModule
but it is possible that handling could be incomplete. If so, would definitely want to fix this.Thank you for reporting the problem!