574c65b3b879d15cd4c353279162690e7b998afe
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / jsonrpc / JsonUtils.java
1 /*
2  * Copyright (c) 2014, 2015 EBay Software Foundation and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.ovsdb.lib.jsonrpc;
9
10 import com.fasterxml.jackson.core.JsonProcessingException;
11 import com.fasterxml.jackson.databind.ObjectMapper;
12 import com.fasterxml.jackson.databind.ObjectWriter;
13
14 public final class JsonUtils {
15     private static final ObjectWriter PRETTY_WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter();
16
17     private JsonUtils() {
18         // Hidden on purpose
19     }
20
21     public static String prettyString(final Object jsonNode) {
22         try {
23             return PRETTY_WRITER.writeValueAsString(jsonNode);
24         } catch (JsonProcessingException e) {
25             throw new IllegalStateException(e);
26         }
27     }
28 }