Explicitly record the generated serialization in a string master
authorKai Moritz <k.moritz@extern.lvm.de>
Tue, 11 Aug 2020 06:48:46 +0000 (08:48 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 15 Aug 2020 16:18:48 +0000 (18:18 +0200)
src/main/java/de/juplo/examples/jackson/SerializationExample.java

index 3b2819c..1da1e7c 100644 (file)
@@ -14,7 +14,9 @@ public class SerializationExample {
        public static void main(String[] args) throws Exception {
                ObjectMapper mapper = new ObjectMapper();
                mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
-               mapper.writeValue(System.out, new Bar());
+               mapper.enable(SerializationFeature.INDENT_OUTPUT);
+               String str = mapper.writeValueAsString(new Bar());
+               System.out.println(str);
        }
 
        static class Foo {