We are not using the Mapper here at all, just the writer. Make sure
we retain only the writer and make it a proper constant (to allow
JIT to do constant propagation).
Change-Id: I7df2a6234511c9dbf51509c495a59e642173fffe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import com.fasterxml.jackson.databind.ObjectWriter;
public final class JsonUtils {
-
- private static ObjectMapper mapper = new ObjectMapper();
- private static ObjectWriter prettyWriter = mapper.writerWithDefaultPrettyPrinter();
+ private static final ObjectWriter PRETTY_WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter();
private JsonUtils() {
}
- public static String prettyString(Object jsonNode) {
+ public static String prettyString(final Object jsonNode) {
try {
- return prettyWriter.writeValueAsString(jsonNode);
+ return PRETTY_WRITER.writeValueAsString(jsonNode);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}