Add support for JacksonAnnotations at bean-properties (#1514)

This commit is contained in:
Roland Praml authored and Rob Bygrave committed 2018-10-25 22:11:36 +13:00
1 parent fecb5fa731
commit 939397acfc
13 files changed
+554 -40

No files matched your search

@@ -223,6 +223,8 @@ public class DeployBeanDescriptor<T> {
private short profileId;
private Object jacksonAnnotatedClass;
/**
* Construct the BeanDescriptor.
*/
@@ -1238,6 +1240,7 @@ public class DeployBeanDescriptor<T> {
this.descriptor = descriptor;
}
@Override
public String getDeployWord(String expression) {
return descriptor.getDeployWord(expression);
}
@@ -1252,4 +1255,16 @@ public class DeployBeanDescriptor<T> {
return (property == null) ? null : "${ta}." + property.getDbColumn();
}
/**
* Returns the jackson annotated class, if jackson is present.
*/
public Object /*AnnotatedClass*/ getJacksonAnnotatedClass() {
if (jacksonAnnotatedClass == null) {
com.fasterxml.jackson.databind.ObjectMapper objectMapper = (com.fasterxml.jackson.databind.ObjectMapper) serverConfig.getObjectMapper();
com.fasterxml.jackson.databind.JavaType javaType = objectMapper.getTypeFactory().constructType(beanType);
jacksonAnnotatedClass = com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver
.resolve(objectMapper.getDeserializationConfig(), javaType, objectMapper.getDeserializationConfig());
}
return jacksonAnnotatedClass;
}
}
@@ -1124,4 +1124,18 @@ public class DeployBeanProperty {
public void setElementProperty() {
this.elementProperty = true;
}
/**
* Returns the jackson annotated field, if jackson is present.
*/
public Object /*AnnotatedField*/ getJacksonField() {
com.fasterxml.jackson.databind.introspect.AnnotatedClass jac =
(com.fasterxml.jackson.databind.introspect.AnnotatedClass) getDesc().getJacksonAnnotatedClass();
for (com.fasterxml.jackson.databind.introspect.AnnotatedField candidate : jac.fields()) {
if (candidate.getName().equals(getName())) {
return candidate;
}
}
return null;
}
}
@@ -239,10 +239,9 @@ public class DeployUtil {
private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength) {
Class<?> type = prop.getPropertyType();
ScalarType<?> scalarType = typeManager.getJsonScalarType(type, dbType, dbLength, prop.getGenericType());
ScalarType<?> scalarType = typeManager.getJsonScalarType(prop, dbType, dbLength);
if (scalarType == null) {
throw new RuntimeException("No ScalarType for JSON type [" + type + "] [" + dbType + "]");
throw new RuntimeException("No ScalarType for JSON property [" + prop + "] [" + dbType + "]");
}
prop.setDbType(dbType);
prop.setScalarType(scalarType);