Merge pull request #1263 from gzeskas/fix-JsonJacksonCoded

JsonJacksonCoded do not override provided objectMapper settings.
pull/1325/head
Nikita Koksharov 7 years ago committed by GitHub
commit 21bb5ca0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -103,9 +103,9 @@ public class JsonJacksonCodec implements Codec {
} }
public JsonJacksonCodec(ObjectMapper mapObjectMapper) { public JsonJacksonCodec(ObjectMapper mapObjectMapper) {
this.mapObjectMapper = mapObjectMapper; this.mapObjectMapper = mapObjectMapper.copy();
init(mapObjectMapper); init(this.mapObjectMapper);
initTypeInclusion(mapObjectMapper); initTypeInclusion(this.mapObjectMapper);
} }
protected void initTypeInclusion(ObjectMapper mapObjectMapper) { protected void initTypeInclusion(ObjectMapper mapObjectMapper) {

@ -2,6 +2,8 @@ package org.redisson.codec;
import java.io.IOException; import java.io.IOException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -34,4 +36,17 @@ public class JsonJacksonCodecTest {
Assert.fail("Should not pass"); Assert.fail("Should not pass");
} }
@Test
public void shouldNotOverrideProvidedObjectMapperProperties() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
JsonJacksonCodec codec = new JsonJacksonCodec(objectMapper);
Assert.assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
Assert.assertFalse(codec.getObjectMapper().getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
Assert.assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
Assert.assertFalse(codec.getObjectMapper().getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
}
} }

Loading…
Cancel
Save