jackson-databind
jackson-databind copied to clipboard
DefaultAccessorNamingStrategy converts to lowercases the whole first group of uppercase characters
Search before asking
- [X] I searched in the issues and found nothing similar.
Describe the bug
Hello, I've noticed that DefaultAccessorNamingStrategy will convert to lowercase more than one letter that follows the prefix of a getter. This is happening in the for-loop here: DefaultAccessorNamingStrategy::legacyManglePropertyName.
Based on the code and comments, this seems to be the intended default behavior, but it can result in unintuitive outcomes.
This was my use case:
@Data
class MyObject {
String iPhone; // <-- lombok generates the getter: getIPhone() {...}
}
If we use the default configuration, the resulting json can be a bit surprising:
{
"iphone": "test"
}
Are there use cases where we can benefit from lowercasing more than one character?
Version Information
latest master version
Reproduction
static class MyObj {
String iPhone;
// constructor
public String getIPhone() {
return iPhone;
}
}
@Test
void lowercasingMoreThanOneChar() throws Exception {
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(new MyObj("test"));
assertEquals("{\"iPhone\":\"test\"}", json); // <- fails, the key will be lowercase: "iphone"
}
Expected behavior
The expected outcome was to lowercase only the first character that follows the 'get' prefix.
Additional context
No response