diff --git a/utils/json/json-lib/src/main/java/com/syntaxphoenix/syntaxapi/json/JsonValue.java b/utils/json/json-lib/src/main/java/com/syntaxphoenix/syntaxapi/json/JsonValue.java index 8ddb76c..c72d2c1 100644 --- a/utils/json/json-lib/src/main/java/com/syntaxphoenix/syntaxapi/json/JsonValue.java +++ b/utils/json/json-lib/src/main/java/com/syntaxphoenix/syntaxapi/json/JsonValue.java @@ -1,8 +1,10 @@ package com.syntaxphoenix.syntaxapi.json; +import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; +import com.syntaxphoenix.syntaxapi.json.io.JsonWriter; import com.syntaxphoenix.syntaxapi.json.value.JsonBigDecimal; import com.syntaxphoenix.syntaxapi.json.value.JsonBigInteger; import com.syntaxphoenix.syntaxapi.json.value.JsonByte; @@ -17,6 +19,9 @@ public abstract class JsonValue { + private static final JsonWriter PRETTY = new JsonWriter().setPretty(true); + private static final JsonWriter UNPRETTY = new JsonWriter(); + @SuppressWarnings("unchecked") public static JsonValue fromPrimitive(E primitive) { if (primitive == null) { @@ -65,4 +70,21 @@ public boolean isPrimitive() { return getType().isPrimitive(); } + @Override + public String toString() { + try { + return UNPRETTY.toString(this); + } catch (IOException e) { + return ""; + } + } + + public String toPrettyString() { + try { + return PRETTY.toString(this); + } catch (IOException e) { + return ""; + } + } + }