Search in sources :

Example 1 with GsonOptions

use of org.immutables.gson.stream.GsonMessageBodyProvider.GsonOptions in project immutables by immutables.

the class JaxrsTest method propagateGsonAttributes.

@Test
public void propagateGsonAttributes() {
    Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().setPrettyPrinting().create();
    GsonOptions options = new GsonOptions(gson, true);
    JsonReader reader = new JsonReader(new StringReader(""));
    options.setReaderOptions(reader);
    check(reader.isLenient());
    JsonWriter writer = new JsonWriter(new StringWriter());
    options.setWriterOptions(writer);
    check(writer.isLenient());
    check(!writer.isHtmlSafe());
    check(writer.getSerializeNulls());
    // checks pretty printing
    check(gson.toJson(Collections.singletonMap("k", "v"))).is("{\n  \"k\": \"v\"\n}");
}
Also used : GsonOptions(org.immutables.gson.stream.GsonMessageBodyProvider.GsonOptions) StringWriter(java.io.StringWriter) GsonBuilder(com.google.gson.GsonBuilder) StringReader(java.io.StringReader) Gson(com.google.gson.Gson) JsonReader(com.google.gson.stream.JsonReader) JsonWriter(com.google.gson.stream.JsonWriter) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonReader (com.google.gson.stream.JsonReader)1 JsonWriter (com.google.gson.stream.JsonWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 GsonOptions (org.immutables.gson.stream.GsonMessageBodyProvider.GsonOptions)1 Test (org.junit.Test)1