#542 - ENH: @DbJson fields are auto serialized and deserialized to specified classes.

This commit is contained in:
Robin Bygrave committed 2016-05-06 13:20:51 +12:00
1 parent deb6ce23d7
commit 13f7d37e76
10 files changed
+516 -19

No files matched your search

@@ -32,6 +32,7 @@ import javax.persistence.Id;
import javax.persistence.Version;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.sql.Types;
/**
@@ -147,6 +148,8 @@ public class DeployBeanProperty {
*/
private final Class<?> propertyType;
private final Type genericType;
/**
* Set for Non-JDBC types to provide logical to db type conversion.
*/
@@ -208,10 +211,17 @@ public class DeployBeanProperty {
public DeployBeanProperty(DeployBeanDescriptor<?> desc, Class<?> propertyType, ScalarType<?> scalarType, ScalarTypeConverter<?, ?> typeConverter) {
this.desc = desc;
this.propertyType = propertyType;
this.genericType = null;
this.scalarType = wrapScalarType(propertyType, scalarType, typeConverter);
this.dbType = (scalarType == null) ? 0 : scalarType.getJdbcType();
}
public DeployBeanProperty(DeployBeanDescriptor<?> desc, Class<?> propertyType, Type genericType) {
this.desc = desc;
this.propertyType = propertyType;
this.genericType = genericType;
}
/**
* Wrap the ScalarType using a ScalarTypeConverter.
*/
@@ -810,6 +820,13 @@ public class DeployBeanProperty {
return propertyType;
}
/**
* Return the generic type for this property.
*/
public Type getGenericType() {
return genericType;
}
/**
* Return true if this is included in the unique id.
*/
@@ -230,7 +230,7 @@ public class DeployCreateProperties {
}
}
if (isSpecialScalarType(field)) {
return new DeployBeanProperty(desc, propertyType, null, null);
return new DeployBeanProperty(desc, propertyType, field.getGenericType());
}
// check for Collection type (list, set or map)
@@ -226,7 +226,7 @@ public class DeployUtil {
private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength) {
Class<?> type = prop.getPropertyType();
ScalarType<?> scalarType = typeManager.getJsonScalarType(type, dbType, dbLength);
ScalarType<?> scalarType = typeManager.getJsonScalarType(type, dbType, dbLength, prop.getGenericType());
if (scalarType == null) {
throw new RuntimeException("No ScalarType for JSON type [" + type + "] [" + dbType + "]");
}