java - System.out messed up after Jackson serialization -
i've been trying serialize objects system.out (for debugging). call
final jsonserializer serializer = new jsonserializer(); serializer.serialize( system.out, myobj ); system.out.println("done");
it prints out json, "done" never gets printed. debugging these lines, shows 3rd line gets executed, output never shows up.
is jackson bug, or doing wrong?
edit:
public class jsonserializer { private objectmapper getconfiguredobjectmapper() { final objectmapper mapper = new objectmapper(); mapper.enable( serializationconfig.feature.indent_output ); mapper.setvisibility( jsonmethod.field, visibility.any ); mapper.setvisibility( jsonmethod.getter, visibility.none ); mapper.configure( serializationconfig.feature.auto_detect_getters, false ); mapper.configure( serializationconfig.feature.auto_detect_is_getters, false ); mapper.configure( serializationconfig.feature.auto_detect_fields, false ); final simplemodule module = new simplemodule( "connectorserialization", new version( 0, 1, 0, null ) ); module.addserializer( new inputconnectorserializer() ); module.addserializer( new outputconnectorserializer() ); module.addserializer( new stateserializer() ); mapper.registermodule( module ); return mapper; } public void serialize( final outputstream outputstream, final object root ) { final objectmapper mapper = getconfiguredobjectmapper(); try { mapper.writevalue( outputstream, root ); } catch (final jsongenerationexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (final jsonmappingexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (final ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
as answers other users got deleted, going answer own question. user stated issue jackson closes input stream automatically.
the solution add jsongenerator.feature.auto_close_target
configuration, , set false:
mapper.configure(jsongenerator.feature.auto_close_target, false);
Comments
Post a Comment