Some small fixes

This commit is contained in:
Ziver Koc 2015-12-12 00:25:17 +01:00
parent 31c700b738
commit 0fae09d687
4 changed files with 10 additions and 6 deletions

BIN
Zutil.jar

Binary file not shown.

12
src/zutil/db/bean/DBBean.java Normal file → Executable file
View file

@ -465,9 +465,8 @@ public abstract class DBBean {
if( !Modifier.isPublic( field.getModifiers()))
field.setAccessible(true);
// Set basic datatype
// Set basic data type
if( o == null && !Object.class.isAssignableFrom( field.getType() ) ){
logger.fine("Trying to set primitive data type to null!");
if( field.getType() == Integer.TYPE ) field.setInt(this, 0);
else if( field.getType() == Character.TYPE )field.setChar(this, (char) 0);
else if( field.getType() == Byte.TYPE ) field.setByte(this, (byte) 0);
@ -477,8 +476,13 @@ public abstract class DBBean {
else if( field.getType() == Double.TYPE ) field.setDouble(this, 0d);
else if( field.getType() == Boolean.TYPE ) field.setBoolean(this, false);
}
else
field.set(this, o);
else {
// Some special cases
if(field.getType() == Boolean.TYPE && o instanceof Integer)
field.setBoolean(this, ((Integer)o) > 0 ); // Convert an Integer to boolean
else
field.set(this, o);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}

View file

@ -418,7 +418,7 @@ public class Templator {
else
str.append(obj.toString());
else
str.append("{{").append(tag).append("}}");
str.append("null");
}
}
}

View file

@ -70,7 +70,7 @@ public class TemplatorTest {
@Test
public void attributeEmptyTest(){
Templator tmpl = new Templator("<HTML>{{test}}</HTML>");
assertEquals("<HTML>{{test}}</HTML>", tmpl.compile());
assertEquals("<HTML>null</HTML>", tmpl.compile());
}
@Test
public void attributeSimpleTest() {