Skip to content

Commit

Permalink
Fix #1977
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 20, 2018
1 parent 1074386 commit ba35c17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project: jackson-databind
(reported by ayushgp@github)
#1947: `MapperFeature.AUTO_DETECT_XXX` do not work if all disabled
(reported by Timur S)
#1977: Serializing an Iterator with multiple sub-types fails after upgrading to 2.9.x
(reported by ssivanand@github)

2.9.4 (24-Jan-2018)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void serializeContents(Iterator<?> value, JsonGenerator g,
protected void _serializeDynamicContents(Iterator<?> value, JsonGenerator g,
SerializerProvider provider) throws IOException
{
JsonSerializer<Object> serializer = _elementSerializer;
final TypeSerializer typeSer = _valueTypeSerializer;
PropertySerializerMap serializers = _dynamicSerializers;
do {
Expand All @@ -106,7 +105,7 @@ protected void _serializeDynamicContents(Iterator<?> value, JsonGenerator g,
continue;
}
Class<?> cc = elem.getClass();
serializers.serializerFor(cc);
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public void testWithIterator() throws IOException
{
assertEquals("{\"values\":[\"itValue\"]}",
STATIC_MAPPER.writeValueAsString(new BeanWithIterator()));

// [databind#1977]
ArrayList<Number> numbersList = new ArrayList<>();
numbersList.add(1);
numbersList.add(0.25);
String json = MAPPER.writeValueAsString(numbersList.iterator());
assertEquals("[1,0.25]", json);
}

// [databind#358]
Expand Down

0 comments on commit ba35c17

Please sign in to comment.