Search in sources :

Example 1 with ThrowableSerializingConverter

use of com.serotonin.json.convert.ThrowableSerializingConverter in project ma-core-public by infiniteautomation.

the class ExceptionTest method main.

public static void main(String[] args) throws Exception {
    JsonContext context = new JsonContext();
    context.addConverter(new ThrowableSerializingConverter(), Throwable.class);
    StringWriter out = new StringWriter();
    JsonWriter writer = new JsonWriter(context, out);
    writer.setPrettyOutput(true);
    writer.writeObject(createException1());
    System.out.println(out);
    JsonReader reader = new JsonReader(context, out.toString());
    Throwable t = reader.read(Throwable.class);
    System.out.println("Great success!");
    System.out.println(t.getMessage());
    t.printStackTrace();
}
Also used : JsonContext(com.serotonin.json.JsonContext) StringWriter(java.io.StringWriter) ThrowableSerializingConverter(com.serotonin.json.convert.ThrowableSerializingConverter) JsonReader(com.serotonin.json.JsonReader) JsonWriter(com.serotonin.json.JsonWriter)

Aggregations

JsonContext (com.serotonin.json.JsonContext)1 JsonReader (com.serotonin.json.JsonReader)1 JsonWriter (com.serotonin.json.JsonWriter)1 ThrowableSerializingConverter (com.serotonin.json.convert.ThrowableSerializingConverter)1 StringWriter (java.io.StringWriter)1