Skip to content

Commit

Permalink
Jackson fix handling of property names from getters
Browse files Browse the repository at this point in the history
  • Loading branch information
npurushe committed Mar 20, 2017
1 parent 521ea10 commit 4b49410
Showing 1 changed file with 13 additions and 1 deletion.
Expand Up @@ -66,7 +66,7 @@ public ObjectIdInfo findObjectIdInfo(Annotated annotated) {
for (Type<?> type : model.getTypes()) {
if (type.getClassType() == rawClass && type.getSingleKeyAttribute() != null) {
Attribute<?, ?> attribute = type.getSingleKeyAttribute();
String name = attribute.getPropertyName();
String name = removePrefix(attribute.getPropertyName());
if (useTableNames) {
name = attribute.getName();
}
Expand Down Expand Up @@ -94,6 +94,18 @@ public ObjectIdInfo findObjectIdInfo(Annotated annotated) {
return super.findObjectIdInfo(annotated);
}

private String removePrefix(String name) {
String[] prefixes = { "get", "is" };
for (String prefix : prefixes) {
if (name.startsWith(prefix) && name.length() > prefix.length()) {
StringBuilder sb = new StringBuilder(name.substring(prefix.length()));
sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
return sb.toString();
}
}
return name;
}

@Override
public PropertyName findNameForDeserialization(Annotated annotated) {
if (useTableNames) {
Expand Down

0 comments on commit 4b49410

Please sign in to comment.