Assuming I have the following object
public class DataObjectA {
private Stream dataObjectBStream;
}
How can I serial
As others have pointed out, you can only iterate once over a stream. If that works for you, you can use this to serialize:
new ObjectMapper().writerFor(Iterator.class).writeValueAsString(dataObjectBStream.iterator())
If you're using a Jackson version prior to 2.5, use writerWithType()
instead of writerFor()
.