From adfc54200fba0bd94ee42f15bc8ca66db1639f43 Mon Sep 17 00:00:00 2001 From: rbygrave Date: Thu, 10 Jun 2021 19:27:42 +1200 Subject: [PATCH] No effective change - extract JacksonTypeHelper for ScalarTypeJsonObjectMapper --- .../server/type/JacksonTypeHelper.java | 46 +++++++++++++++++++ .../type/ScalarTypeJsonObjectMapper.java | 35 ++------------ 2 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/type/JacksonTypeHelper.java diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/JacksonTypeHelper.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/JacksonTypeHelper.java new file mode 100644 index 000000000..1e1db244d --- /dev/null +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/JacksonTypeHelper.java @@ -0,0 +1,46 @@ +package io.ebeaninternal.server.type; + +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.introspect.AnnotatedField; + +class JacksonTypeHelper { + + private final AnnotatedField field; + private final ObjectMapper objectMapper; + private final JavaType javaType; + private final DeserializationConfig deserConfig; + private final AnnotationIntrospector ai; + + JacksonTypeHelper(AnnotatedField field, ObjectMapper objectMapper) { + this.field = field; + this.objectMapper = objectMapper; + this.javaType = field.getType(); + this.deserConfig = objectMapper.getDeserializationConfig(); + this.ai = deserConfig.getAnnotationIntrospector(); + } + + JavaType type() { + if (ai == null || javaType == null || javaType.hasRawClass(Object.class)) { + return javaType; + } else { + try { + return ai.refineDeserializationType(deserConfig, field, javaType); + } catch (JsonMappingException e) { + throw new RuntimeException(e); + } + } + } + + ObjectWriter objectWriter() { + if (ai == null || javaType == null || javaType.hasRawClass(Object.class)) { + return objectMapper.writerFor(javaType); + } else { + try { + JavaType serType = ai.refineSerializationType(objectMapper.getSerializationConfig(), field, javaType); + return objectMapper.writerFor(serType); + } catch (JsonMappingException e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java index b001e5ddf..3cf05d9c2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java @@ -3,13 +3,9 @@ package io.ebeaninternal.server.type; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.AnnotationIntrospector; -import com.fasterxml.jackson.databind.DeserializationConfig; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.SerializationConfig; import com.fasterxml.jackson.databind.introspect.AnnotatedField; import io.ebean.config.dbplatform.DbPlatformType; import io.ebean.core.type.DataBinder; @@ -156,34 +152,9 @@ public class ScalarTypeJsonObjectMapper { this.pgType = pgType; this.docType = docType; this.objectReader = objectMapper; - - JavaType javaType = field.getType(); - DeserializationConfig deserConfig = objectMapper.getDeserializationConfig(); - AnnotationIntrospector ai = deserConfig.getAnnotationIntrospector(); - - if (ai != null && javaType != null && !javaType.hasRawClass(Object.class)) { - try { - this.deserType = ai.refineDeserializationType(deserConfig, field, javaType); - } catch (JsonMappingException e) { - throw new RuntimeException(e); - } - } else { - this.deserType = javaType; - } - - SerializationConfig serConfig = objectMapper.getSerializationConfig(); - ai = deserConfig.getAnnotationIntrospector(); - - if (ai != null && javaType != null && !javaType.hasRawClass(Object.class)) { - try { - JavaType serType = ai.refineSerializationType(serConfig, field, javaType); - this.objectWriter = objectMapper.writerFor(serType); - } catch (JsonMappingException e) { - throw new RuntimeException(e); - } - } else { - this.objectWriter = objectMapper.writerFor(javaType); - } + final JacksonTypeHelper helper = new JacksonTypeHelper(field, objectMapper); + this.deserType = helper.type(); + this.objectWriter = helper.objectWriter(); } /**