try {
if ( ctx.isWrapRootValue() ) {
writer.beginObject();
writer.name( rootName );
getSerializer().serialize( writer, value, ctx );
writer.endObject();
} else {
getSerializer().serialize( writer, value, ctx );
}
return writer.getOutput();
} catch ( JsonSerializationException e ) {