diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 461d6edead..e2221f94cd 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -571,6 +571,10 @@ Nathanial Ofiesh (ofiesh@github) * Reported #1441: Failure with custom Enum key deserializer, polymorphic types (2.8.5) +Frédéric Camblor (fcamblor@github) + * Reported #1451: Type parameter not passed by `ObjectWriter` if serializer pre-fetch disabled + (2.8.6) + Connor Kuhn (ckuhn@github) * Contributed #1341: FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY (2.9.0) diff --git a/release-notes/VERSION b/release-notes/VERSION index 2227c56694..d5b3d1457d 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -134,6 +134,11 @@ Project: jackson-databind #1432: Off by 1 bug in PropertyValueBuffer (reported by Kevin D) #1439: NPE when using with filter id, serializing `java.util.Map` types +#1451: Type parameter not passed by `ObjectWriter` if serializer pre-fetch disabled + (reported by Frédéric C) +#1456: `TypeFactory` type resolution broken in 2.7 for generic types + when using `constructType` with context + (reported by Dmitry S) 2.7.8 (26-Sep-2016) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java index 958449c772..3a6988b781 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java @@ -1401,7 +1401,7 @@ public Prefetch forRootType(ObjectWriter parent, JavaType newType) { ; } } - return new Prefetch(null, null, typeSerializer); + return new Prefetch(newType, null, typeSerializer); } public final JsonSerializer getValueSerializer() { @@ -1421,13 +1421,13 @@ public void serialize(JsonGenerator gen, Object value, DefaultSerializerProvider { if (typeSerializer != null) { prov.serializePolymorphic(gen, value, rootType, valueSerializer, typeSerializer); - return; - } - if (valueSerializer != null) { + } else if (valueSerializer != null) { prov.serializeValue(gen, value, rootType, valueSerializer); - return; + } else if (rootType != null) { + prov.serializeValue(gen, value, rootType); + } else { + prov.serializeValue(gen, value); } - prov.serializeValue(gen, value); } } } diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/PolymorphicList1451SerTest.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/PolymorphicList1451SerTest.java new file mode 100644 index 0000000000..6617c0b336 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/PolymorphicList1451SerTest.java @@ -0,0 +1,53 @@ +package com.fasterxml.jackson.databind.jsontype; + +import java.util.*; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.*; + +public class PolymorphicList1451SerTest extends BaseMapTest +{ + @JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") + public static class A { + public String a; + } + public static class B extends A { + public String b; + } + + private final String CLASS_NAME = getClass().getSimpleName(); + + public void testCollectionWithTypeInfo() throws Exception { + ObjectMapper mapper = new ObjectMapper() + .disable(SerializationFeature.EAGER_SERIALIZER_FETCH) +// .disable(DeserializationFeature.EAGER_DESERIALIZER_FETCH) + ; + + List input = new ArrayList(); + A a = new A(); + a.a = "a1"; + input.add(a); + + B b = new B(); + b.b = "b"; + b.a = "a2"; + input.add(b); + + final TypeReference typeRef = + new TypeReference>(){}; + ObjectWriter writer = mapper.writerFor(typeRef); + + String result = writer.writeValueAsString(input); + + assertEquals(aposToQuotes( +"[{'@class':'."+CLASS_NAME+"$A','a':'a1'},{'@class':'."+CLASS_NAME+"$B','a':'a2','b':'b'}]" +), result); + + List output = mapper.readerFor(typeRef) + .readValue(result); + assertEquals(2, output.size()); + assertEquals(A.class, output.get(0).getClass()); + assertEquals(B.class, output.get(1).getClass()); + } +}