From 84d82a1390d8c417dbde8f36520d80a1188b8c61 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 9 Jun 2022 08:27:20 +0300 Subject: [PATCH] refactoring --- .../org/redisson/codec/JsonJacksonCodec.java | 11 ++++++++- .../redisson/codec/TypedJsonJacksonCodec.java | 24 +++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/redisson/src/main/java/org/redisson/codec/JsonJacksonCodec.java b/redisson/src/main/java/org/redisson/codec/JsonJacksonCodec.java index a6d4e4c52..123cd9557 100755 --- a/redisson/src/main/java/org/redisson/codec/JsonJacksonCodec.java +++ b/redisson/src/main/java/org/redisson/codec/JsonJacksonCodec.java @@ -136,7 +136,16 @@ public class JsonJacksonCodec extends BaseCodec { } public JsonJacksonCodec(ObjectMapper mapObjectMapper) { - this.mapObjectMapper = mapObjectMapper.copy(); + this(mapObjectMapper, true); + warmup(); + } + + public JsonJacksonCodec(ObjectMapper mapObjectMapper, boolean copy) { + if (copy) { + this.mapObjectMapper = mapObjectMapper.copy(); + } else { + this.mapObjectMapper = mapObjectMapper; + } init(this.mapObjectMapper); initTypeInclusion(this.mapObjectMapper); warmup(); diff --git a/redisson/src/main/java/org/redisson/codec/TypedJsonJacksonCodec.java b/redisson/src/main/java/org/redisson/codec/TypedJsonJacksonCodec.java index df745de20..7b91e0b8f 100644 --- a/redisson/src/main/java/org/redisson/codec/TypedJsonJacksonCodec.java +++ b/redisson/src/main/java/org/redisson/codec/TypedJsonJacksonCodec.java @@ -83,7 +83,8 @@ public class TypedJsonJacksonCodec extends JsonJacksonCodec { private final Class mapValueClass; public TypedJsonJacksonCodec(Class valueClass) { - this(valueClass, new ObjectMapper()); + this(null, null, null, + valueClass, null, null, new ObjectMapper(), false); } public TypedJsonJacksonCodec(Class valueClass, ObjectMapper mapper) { @@ -99,11 +100,13 @@ public class TypedJsonJacksonCodec extends JsonJacksonCodec { } public TypedJsonJacksonCodec(Class valueClass, Class mapKeyClass, Class mapValueClass) { - this(null, null, null, valueClass, mapKeyClass, mapValueClass, new ObjectMapper()); + this(null, null, null, + valueClass, mapKeyClass, mapValueClass, new ObjectMapper(), false); } public TypedJsonJacksonCodec(Class valueClass, Class mapKeyClass, Class mapValueClass, ObjectMapper mapper) { - this(null, null, null, valueClass, mapKeyClass, mapValueClass, mapper); + this(null, null, null, + valueClass, mapKeyClass, mapValueClass, mapper, true); } public TypedJsonJacksonCodec(TypeReference valueTypeReference) { @@ -123,23 +126,24 @@ public class TypedJsonJacksonCodec extends JsonJacksonCodec { } public TypedJsonJacksonCodec(TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference) { - this(valueTypeReference, mapKeyTypeReference, mapValueTypeReference, null, null, null, new ObjectMapper()); + this(valueTypeReference, mapKeyTypeReference, mapValueTypeReference, + null, null, null, new ObjectMapper(), false); } public TypedJsonJacksonCodec(TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference, ObjectMapper mapper) { - this(valueTypeReference, mapKeyTypeReference, mapValueTypeReference, null, null, null, mapper); + this(valueTypeReference, mapKeyTypeReference, mapValueTypeReference, + null, null, null, mapper, true); } public TypedJsonJacksonCodec(ClassLoader classLoader, TypedJsonJacksonCodec codec) { this(codec.valueTypeReference, codec.mapKeyTypeReference, codec.mapValueTypeReference, codec.valueClass, codec.mapKeyClass, codec.mapValueClass, - createObjectMapper(classLoader, codec.mapObjectMapper.copy())); + createObjectMapper(classLoader, codec.mapObjectMapper.copy()), false); } - TypedJsonJacksonCodec( - TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference, - Class valueClass, Class mapKeyClass, Class mapValueClass, ObjectMapper mapper) { - super(mapper); + TypedJsonJacksonCodec(TypeReference valueTypeReference, TypeReference mapKeyTypeReference, TypeReference mapValueTypeReference, + Class valueClass, Class mapKeyClass, Class mapValueClass, ObjectMapper mapper, boolean copy) { + super(mapper, copy); this.mapValueDecoder = createDecoder(mapValueClass, mapValueTypeReference); this.mapKeyDecoder = createDecoder(mapKeyClass, mapKeyTypeReference); this.valueDecoder = createDecoder(valueClass, valueTypeReference);