mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Extract ebean-jackson-mapper module - refactor DefaultTypeManager.dbJsonType()
- When detected markerAnnotation (e.g. Jackson annotation) then go directly to createJsonObjectMapperType() - Simplify for the simple List, Set and Map of Object cases.
This commit is contained in:
1 parent
610b3f7dc8
commit
318b22448c
1 file changed
+12
-23
@@ -300,36 +300,21 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
if (type.equals(String.class)) {
|
if (type.equals(String.class)) {
|
||||||
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
||||||
}
|
}
|
||||||
boolean hasJacksonAnnotations = false;
|
|
||||||
if (jsonMapper != null) {
|
if (jsonMapper != null) {
|
||||||
var markerAnnotation = jsonMapper.markerAnnotation();
|
var markerAnnotation = jsonMapper.markerAnnotation();
|
||||||
if (markerAnnotation != null) {
|
if (markerAnnotation != null && !prop.getMetaAnnotations(markerAnnotation).isEmpty()) {
|
||||||
hasJacksonAnnotations = !prop.getMetaAnnotations(markerAnnotation).isEmpty();
|
return createJsonObjectMapperType(prop, dbType, docPropertyType(prop, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Type genericType = prop.getGenericType();
|
Type genericType = prop.getGenericType();
|
||||||
if (type.equals(List.class)) {
|
if (type.equals(List.class) && isValueTypeSimple(genericType)) {
|
||||||
DocPropertyType docType = docType(genericType);
|
return ScalarTypeJsonList.typeFor(postgres, dbType, docType(genericType), prop.isNullable(), keepSource(prop));
|
||||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
|
||||||
return ScalarTypeJsonList.typeFor(postgres, dbType, docType, prop.isNullable(), keepSource(prop));
|
|
||||||
} else {
|
|
||||||
return createJsonObjectMapperType(prop, dbType, docType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (type.equals(Set.class)) {
|
if (type.equals(Set.class) && isValueTypeSimple(genericType)) {
|
||||||
DocPropertyType docType = docType(genericType);
|
return ScalarTypeJsonSet.typeFor(postgres, dbType, docType(genericType), prop.isNullable(), keepSource(prop));
|
||||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
|
||||||
return ScalarTypeJsonSet.typeFor(postgres, dbType, docType, prop.isNullable(), keepSource(prop));
|
|
||||||
} else {
|
|
||||||
return createJsonObjectMapperType(prop, dbType, docType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (type.equals(Map.class)) {
|
if (type.equals(Map.class) && isMapValueTypeObject(genericType)) {
|
||||||
if (!hasJacksonAnnotations && isMapValueTypeObject(genericType)) {
|
return ScalarTypeJsonMap.typeFor(postgres, dbType, keepSource(prop));
|
||||||
return ScalarTypeJsonMap.typeFor(postgres, dbType, keepSource(prop));
|
|
||||||
} else {
|
|
||||||
return createJsonObjectMapperType(prop, dbType, DocPropertyType.OBJECT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (objectMapperPresent && prop.getMutationDetection() == MutationDetection.DEFAULT) {
|
if (objectMapperPresent && prop.getMutationDetection() == MutationDetection.DEFAULT) {
|
||||||
ScalarTypeSet<?> typeSet = typeSets.get(type);
|
ScalarTypeSet<?> typeSet = typeSets.get(type);
|
||||||
@@ -347,6 +332,10 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
return prop.getMutationDetection() == MutationDetection.SOURCE;
|
return prop.getMutationDetection() == MutationDetection.SOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DocPropertyType docPropertyType(DeployBeanProperty prop, Class<?> type) {
|
||||||
|
return type.equals(List.class) || type.equals(Set.class) ? docType(prop.getGenericType()) : DocPropertyType.OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
private DocPropertyType docType(Type genericType) {
|
private DocPropertyType docType(Type genericType) {
|
||||||
if (genericType instanceof Class<?>) {
|
if (genericType instanceof Class<?>) {
|
||||||
ScalarType<?> found = type((Class<?>) genericType);
|
ScalarType<?> found = type((Class<?>) genericType);
|
||||||
|
|||||||
Reference in new issue
Block a user