Skip to content

Commit

Permalink
Prefix boolean bean properties with "is_" only for methods that start…
Browse files Browse the repository at this point in the history
… with "is"
  • Loading branch information
Tom McClure committed Nov 30, 2018
1 parent 2ba8b12 commit 527877f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/x5/util/ObjectDataMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public Getter(PropertyDescriptor property, Method getter)

String paramName = property.getName();
paramName = splitCamelCase(paramName);
if (this.valueClass.toString().equalsIgnoreCase("boolean")) {
if (getter.getName().startsWith("is")) {
paramName = "is_"+paramName;
}
this.name = paramName;
Expand Down Expand Up @@ -575,7 +575,7 @@ public Map<String,Object> mapifyBean(Object bean)
// converts getBookTitle() to book_title
String paramName = property.getName();
paramName = splitCamelCase(paramName);
if (paramValue instanceof Boolean) {
if (getter.getName().startsWith("is")) {
paramName = "is_"+paramName;
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/x5/template/ChunkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,19 @@ public void snakeCaseTest()
assertEquals("snake2_xml_case", ObjectDataMap.splitCamelCase("Snake2XMLCase"));
}

@Test
public void beanBooleanTest()
{
Theme theme = new Theme();
Chunk c = theme.makeChunk();
c.append("{$x.is_active|ondefined(Active):Inactive}");
c.append(" {$x.has_lemons|ondefined(Lemon-Ready):Lemonless}");
ThingBean bean = new ThingBean();
c.set("x", bean);
bean.setActive(true);
assertEquals("Active Lemonless", c.toString());
}

@Test
public void circularPOJOTest()
{
Expand Down Expand Up @@ -1058,6 +1071,7 @@ public static class ThingBean implements java.io.Serializable, Cloneable
private double pi = Math.PI;
private Double e = new Double(Math.E);
private boolean isActive;
private boolean hasLemons;
private ThingBean boss;
private ThingBean[] children;

Expand Down Expand Up @@ -1103,6 +1117,11 @@ public boolean isActive()
return isActive;
}

public Boolean getHasLemons()
{
return hasLemons;
}

public ThingBean getBoss()
{
return boss;
Expand Down

0 comments on commit 527877f

Please sign in to comment.