Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lombok boolean getter style support (isBoolean()) #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>

<dependency>
<scope>test</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
</dependencies>

<build>
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/sql2o/reflection/PojoMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ private PropertyAndFieldInfo initializePropertyInfo() {
propertyGetters.put(propertyName, factoryFacade.newGetter(m));
}

if (m.getName().startsWith("is")) {
String propertyName = m.getName().substring(2);
if (caseSensitive) {
propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);
} else {
propertyName = propertyName.toLowerCase();
}

propertyGetters.put(propertyName, factoryFacade.newGetter(m));
}

if (m.getName().startsWith("set") && m.getParameterTypes().length == 1) {
String propertyName = readAnnotatedColumnName(m, isJpaColumnInClasspath);
if(propertyName == null) {
Expand Down
31 changes: 31 additions & 0 deletions core/src/test/java/org/sql2o/reflect/ReadLombokAnnotationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.sql2o.reflect;

import com.google.common.collect.ImmutableMap;
import junit.framework.TestCase;
import lombok.Data;
import org.junit.Test;
import org.sql2o.reflection.PojoMetadata;

@SuppressWarnings("unused")
public class ReadLombokAnnotationTest
extends TestCase {

@Test
public void testBooleanGetter() {
PojoMetadata metadata = newPojoMetadata(BooleanAnnotation.class);
assertNotNull(metadata.getPropertyGetterIfExists("field1"));
assertNotNull(metadata.getPropertyGetterIfExists("field2"));
}

private PojoMetadata newPojoMetadata(Class<?> clazz) {
return new PojoMetadata(clazz, false, false, ImmutableMap.<String, String> of(), true);
}

@Data
private static class BooleanAnnotation {
private boolean field1;
private Boolean field2;
}


}