[#3101] MutablePOJOMapper doesn't work with annotated boolean getters

This commit is contained in:
Lukas Eder 2014-03-07 15:14:41 +01:00
parent e69300b114
commit fb8a978dcb
2 changed files with 113 additions and 2 deletions

View File

@ -1758,10 +1758,15 @@ final class Utils {
// Annotated getter with matching setter
else if (method.getParameterTypes().length == 0) {
String m = method.getName();
String suffix = m.startsWith("get")
? m.substring(3)
: m.startsWith("is")
? m.substring(2)
: null;
if (m.startsWith("get") || m.startsWith("is")) {
if (suffix != null) {
try {
Method setter = type.getMethod("set" + m.substring(3), method.getReturnType());
Method setter = type.getMethod("set" + suffix, method.getReturnType());
// Setter annotation is more relevant
if (setter.getAnnotation(Column.class) == null) {

View File

@ -0,0 +1,106 @@
/**
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This work is dual-licensed
* - under the Apache Software License 2.0 (the "ASL")
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
* =============================================================================
* You may choose which license applies to you:
*
* - If you're using this work with Open Source databases, you may choose
* either ASL or jOOQ License.
* - If you're using this work with at least one commercial database, you must
* choose jOOQ License
*
* For more information, please visit http://www.jooq.org/licenses
*
* Apache Software License 2.0:
* -----------------------------------------------------------------------------
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* jOOQ License and Maintenance Agreement:
* -----------------------------------------------------------------------------
* Data Geekery grants the Customer the non-exclusive, timely limited and
* non-transferable license to install and use the Software under the terms of
* the jOOQ License and Maintenance Agreement.
*
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
*/
package org.jooq.test;
import static junit.framework.Assert.assertTrue;
import static org.jooq.impl.DSL.field;
import javax.persistence.Column;
import org.jooq.Field;
import org.jooq.Record1;
import org.junit.Test;
/**
* A test suite for jOOQ functionality related to records
*
* @author Lukas Eder
*/
public class RecordMappingTest extends AbstractTest {
@Test
public void testIntoBooleans() throws Exception {
Field<Boolean> field = field("B", Boolean.class);
Record1<Boolean> record = create.newRecord(field);
record.setValue(field, true);
// [#3101] Make sure this works for both "get" and "is" annotated getters
BooleansWithAnnotations pojo = record.into(BooleansWithAnnotations.class);
assertTrue(pojo.oneZero);
assertTrue(pojo.oneZero1);
assertTrue(pojo.oneZero2);
}
public static class BooleansWithAnnotations {
@Column(name = "B")
public boolean oneZero;
public boolean oneZero1;
public boolean oneZero2;
public void setOneZero1(boolean oneZero1) {
this.oneZero1 = oneZero1;
}
@Column(name = "B")
public boolean getOneZero1() {
return oneZero1;
}
public void setOneZero2(boolean oneZero2) {
this.oneZero2 = oneZero2;
}
@Column(name = "B")
public boolean isOneZero2() {
return oneZero2;
}
@Override
public String toString() {
return "Boolean [oneZero=" + oneZero + ", oneZero1=" + oneZero1 + ", oneZero2=" + oneZero2 + "]";
}
}
}