From c2fc775b01d65396f152b5654130b1736a9d4af2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Aug 2020 08:48:46 +0200 Subject: [PATCH] Explicitly record the generated serialization in a string --- .../java/de/juplo/examples/jackson/SerializationExample.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/juplo/examples/jackson/SerializationExample.java b/src/main/java/de/juplo/examples/jackson/SerializationExample.java index 3b2819c..1da1e7c 100644 --- a/src/main/java/de/juplo/examples/jackson/SerializationExample.java +++ b/src/main/java/de/juplo/examples/jackson/SerializationExample.java @@ -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 { -- 2.20.1