Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 18, 2016
2 parents ab9fcac + 002a9a3 commit 61fe53a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> getValueSerializer() {
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<A> input = new ArrayList<A>();
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<Collection<A>>(){};
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<A> output = mapper.readerFor(typeRef)
.readValue(result);
assertEquals(2, output.size());
assertEquals(A.class, output.get(0).getClass());
assertEquals(B.class, output.get(1).getClass());
}
}

0 comments on commit 61fe53a

Please sign in to comment.