Skip to content

Commit

Permalink
Fix FasterXML#924 - SequenceWriter.writeAll() could accept also Iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
jkremser committed Nov 4, 2015
1 parent ecbf40f commit 1d8124b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/com/fasterxml/jackson/databind/SequenceWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,18 @@ public SequenceWriter writeAll(Object[] value) throws IOException
return this;
}

/**
* This method can be removed in the next major release.
*
* @deprecated use {@link #writeAll(Iterable)} instead.
*/
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException
{
for (Object value : container) {
return writeAll((Iterable) container);
}

public <I extends Iterable<?>> SequenceWriter writeAll(I iterable) throws IOException {
for (Object value : iterable) {
write(value);
}
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.databind.seq;

import java.io.StringWriter;
import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
Expand Down Expand Up @@ -75,6 +76,17 @@ public void testSimpleArray() throws Exception
strw.toString());
}

public void testSimpleIterable() throws Exception {
StringWriter strw = new StringWriter();
SequenceWriter w = WRITER.writeValuesAsArray(strw);
Iterable<Bean> iterable = Arrays.asList(new Bean(3), new Bean(3), new Bean(7));
w.write(new Bean(1))
.writeAll(iterable);
w.close();
assertEquals(aposToQuotes("[{'a':1},{'a':3},{'a':3},{'a':7}]"),
strw.toString());
}

/*
/**********************************************************
/* Test methods, polymorphic writes
Expand Down

0 comments on commit 1d8124b

Please sign in to comment.