Skip to content

Commit

Permalink
Merge pull request #62 from pareshd/getfix
Browse files Browse the repository at this point in the history
Fix for issue (#61): Any appearance of "get" in property name is replaced with empty string
  • Loading branch information
monitorjbl committed Nov 28, 2018
2 parents 733c66d + 24c01d6 commit 27367e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Expand Up @@ -791,7 +791,7 @@ private String getFieldName(AccessibleProperty property) {
}

private String getFieldNameFromGetter(Method method) {
String name = method.getName().replace("get", "");
String name = method.getName().replaceFirst("get", "");
return name.substring(0, 1).toLowerCase() + name.substring(1);
}

Expand Down
Expand Up @@ -1147,5 +1147,18 @@ public void testDuplicateKeysOnInheritance() throws Exception {

assertEquals(ref.getId(), obj.get("id"));
}

@Test
public void testFieldWithGetInName() throws IOException {
TestObject ref = new TestObject();
ref.setInt1(1);
ref.setWidgetName("random name");
String serialized = sut.writeValueAsString(
JsonView.with(ref).onClass(TestObject.class, match()));

Map<String, Object> obj = sut.readValue(serialized, NonReplacableKeyMap.class);
assertNull(obj.get("widName"));
assertNotNull(obj.get("widgetName"));
}

}
Expand Up @@ -62,6 +62,7 @@ public enum TestEnum {VALUE_A, VALUE_B}
private UUID uuid;
private TestObject recursion;
private JsonNode jsonNode;
private String widgetName;

public String getStr1() {
return str1;
Expand Down Expand Up @@ -319,4 +320,12 @@ public String getStaticValue() {
public String getIgnoredValue() {
return "not_valid";
}

public String getWidgetName() {
return widgetName;
}

public void setWidgetName(String widgetName) {
this.widgetName = widgetName;
}
}

0 comments on commit 27367e7

Please sign in to comment.