Is there a way to make Jackson serialize some stream object (and close after)? like this:
class TextFile{
String fileName;
StringReader content;
//ByteArrayInputStream content;
}
Update
Clarification: I want to stream the content, not just serialize it to a single String object.
Implement a custom JsonSerializer:
public class StreamSerializer extends JsonSerializer<ByteArrayInputStream> {
@Override
public void serialize(ByteArrayInputStream content,
JsonGenerator jsonGenerator,
SerializerProvider serializerProvider)
throws IOException, JsonProcessingException {
jsonGenerator.writeBinary(content, -1);
}
And use it like this:
public class TextFile {
String fileName;
@JsonSerialize(using=StreamSerializer.class, as=byte[].class)
ByteArrayInputStream content;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With