From 7e507d11e32a68aaeee743b3d6d07a213a6d1677 Mon Sep 17 00:00:00 2001 From: Cowtowncoder Date: Fri, 6 Feb 2015 15:22:29 -0800 Subject: [PATCH] Fixed #696 --- release-notes/CREDITS | 4 ++++ release-notes/VERSION | 2 ++ .../com/fasterxml/jackson/databind/ObjectMapper.java | 11 ++++++++++- .../com/fasterxml/jackson/databind/ObjectReader.java | 9 ++++++++- .../fasterxml/jackson/databind/TestObjectMapper.java | 5 +++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 655d66f2a7..76d9a72c1a 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -203,3 +203,7 @@ Zoltan Farkas (zolyfarkas@github) Ludevik@github: * Reported #682: Class-valued Map keys not serialized properly (2.5.1) + +Charles Allen (drcrallen@github) + * Reported #696: Copy constructor does not preserve `_injectableValues` + (2.6.0) diff --git a/release-notes/VERSION b/release-notes/VERSION index 4903620951..6696fb3b12 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -7,6 +7,8 @@ Project: jackson-databind 2.6.0 (not yet released) #649: Make `BeanDeserializer` use new `parser.nextFieldName()` and `.hasTokenId()` methods +#696: Copy constructor does not preserve `_injectableValues` + (reported by Charles A) 2.5.1 (not yet released) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index c581d661cc..25acf68a4a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -412,6 +412,8 @@ protected ObjectMapper(ObjectMapper src) _subtypeResolver = src._subtypeResolver; _rootNames = new RootNameLookup(); _typeFactory = src._typeFactory; + _injectableValues = src._injectableValues; + HashMap> mixins = new HashMap>(src._mixInAnnotations); _mixInAnnotations = mixins; _serializationConfig = new SerializationConfig(src._serializationConfig, mixins); @@ -1522,7 +1524,14 @@ public ObjectMapper setInjectableValues(InjectableValues injectableValues) { _injectableValues = injectableValues; return this; } - + + /** + * @since 2.6 + */ + public InjectableValues getInjectableValues() { + return _injectableValues; + } + /** * Method for overriding default locale to use for formatting. * Default value used is {@link Locale#getDefault()}. diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java b/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java index 3cbe124ec6..950408ccd5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java @@ -834,7 +834,14 @@ public TypeFactory getTypeFactory() { public ContextAttributes getAttributes() { return _config.getAttributes(); } - + + /** + * @since 2.6 + */ + public InjectableValues getInjectableValues() { + return _injectableValues; + } + /* /********************************************************** /* Deserialization methods; basic ones to support ObjectCodec first diff --git a/src/test/java/com/fasterxml/jackson/databind/TestObjectMapper.java b/src/test/java/com/fasterxml/jackson/databind/TestObjectMapper.java index ce9056f5a7..1a3758c00a 100644 --- a/src/test/java/com/fasterxml/jackson/databind/TestObjectMapper.java +++ b/src/test/java/com/fasterxml/jackson/databind/TestObjectMapper.java @@ -47,6 +47,7 @@ public void testProps() assertNotNull(m.getNodeFactory()); JsonNodeFactory nf = JsonNodeFactory.instance; m.setNodeFactory(nf); + assertNull(m.getInjectableValues()); assertSame(nf, m.getNodeFactory()); } @@ -138,6 +139,8 @@ public void testCopy() throws Exception assertTrue(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); m.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); assertFalse(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); + InjectableValues inj = new InjectableValues.Std(); + m.setInjectableValues(inj); // // First: verify that handling of features is decoupled: @@ -145,6 +148,8 @@ public void testCopy() throws Exception assertFalse(m2.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); m2.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); assertTrue(m2.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); + assertSame(inj, m2.getInjectableValues()); + // but should NOT change the original assertFalse(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));