@Test public void testJsonOptions() { TestGsonConfiguration.AnnotatedDoc testDoc = new TestGsonConfiguration.AnnotatedDoc(); testDoc.value = new TestGsonConfiguration.SomeComplexObject("complexA", "complexB"); testDoc.sensitivePropertyOptions = "sensitive data1"; testDoc.sensitiveUsageOption = "sensitive data2"; Pattern containsWhitespacePattern = Pattern.compile("\\s"); String jsonIncludeSensitiveAndBuiltInPrettyPrinted = Utils.toJson(EnumSet.noneOf(JsonMapper.JsonOptions.class), testDoc); assertThat(jsonIncludeSensitiveAndBuiltInPrettyPrinted, containsString("complexA")); assertThat(jsonIncludeSensitiveAndBuiltInPrettyPrinted, containsString("sensitive")); assertThat(jsonIncludeSensitiveAndBuiltInPrettyPrinted, containsString(ServiceDocument.FIELD_NAME_VERSION)); assertTrue("pretty-printed JSON should have whitespaces", containsWhitespacePattern.matcher(jsonIncludeSensitiveAndBuiltInPrettyPrinted).find()); String jsonExcludeSensitiveIncludesBuiltIn = Utils.toJson(EnumSet.of(JsonMapper.JsonOptions.EXCLUDE_SENSITIVE), testDoc); assertThat(jsonExcludeSensitiveIncludesBuiltIn, containsString("complexA")); assertThat(jsonExcludeSensitiveIncludesBuiltIn, not(containsString("sensitive"))); assertThat(jsonExcludeSensitiveIncludesBuiltIn, containsString(ServiceDocument.FIELD_NAME_VERSION)); String jsonIncludeSensitiveExcludeBuiltIn = Utils.toJson(EnumSet.of(JsonMapper.JsonOptions.EXCLUDE_BUILTIN), testDoc); assertThat(jsonIncludeSensitiveExcludeBuiltIn, containsString("complexA")); assertThat(jsonIncludeSensitiveExcludeBuiltIn, containsString("sensitive")); assertThat(jsonIncludeSensitiveExcludeBuiltIn, not(containsString(ServiceDocument.FIELD_NAME_VERSION))); String jsonExcludeSensitiveAndBuiltInCompact = Utils.toJson( EnumSet.of(JsonMapper.JsonOptions.EXCLUDE_SENSITIVE, JsonMapper.JsonOptions.EXCLUDE_BUILTIN, JsonMapper.JsonOptions.COMPACT), testDoc); assertThat(jsonExcludeSensitiveAndBuiltInCompact, containsString("complexA")); assertThat(jsonExcludeSensitiveAndBuiltInCompact, not(containsString("sensitive"))); assertThat(jsonExcludeSensitiveAndBuiltInCompact, not(containsString(ServiceDocument.FIELD_NAME_VERSION))); assertFalse("compact JSON should not have whitespaces", containsWhitespacePattern.matcher(jsonExcludeSensitiveAndBuiltInCompact).find()); }
public String toJson(Object body) { for (int i = 1; ; i++) { try { return this.compact.toJson(body); } catch (IllegalStateException e) { handleIllegalStateException(e, i); } } }
JsonMapper { public String toJson(Object body) { for (int i = 1; ; i++) { try { return this.compact.toJson(body); } catch (IllegalStateException e) { handleIllegalStateException(e, i); } } } }
JsonMapper { public String toJson(Object body) { for (int i = 1; ; i++) { try { return this.compact.toJson(body); } catch (IllegalStateException e) { handleIllegalStateException(e, i); } } } JsonMapper();  JsonMapper(Consumer<GsonBuilder> gsonConfigCallback);  JsonMapper(Gson compact, Gson compactSensitive); }
JsonMapper { public String toJson(Object body) { for (int i = 1; ; i++) { try { return this.compact.toJson(body); } catch (IllegalStateException e) { handleIllegalStateException(e, i); } } } JsonMapper();  JsonMapper(Consumer<GsonBuilder> gsonConfigCallback);  JsonMapper(Gson compact, Gson compactSensitive); String toJson(Object body); void toJson(Object body, Appendable appendable); JsonElement toJsonElement(Object body); String toJsonHtml(Object body); void toJson(Set<JsonOptions> options, Object body, Appendable appendable); T fromJson(Object json, Class<T> clazz); T fromJson(Object json, Type type); void setJsonSuppressGsonSerializationErrors(boolean suppressErrors); static GsonBuilder createDefaultGsonBuilder(EnumSet<JsonOptions> options); void toJsonHtml(Object body, Appendable appendable); long hashJson(Object body, long seed); }
JsonMapper { public String toJson(Object body) { for (int i = 1; ; i++) { try { return this.compact.toJson(body); } catch (IllegalStateException e) { handleIllegalStateException(e, i); } } } JsonMapper();  JsonMapper(Consumer<GsonBuilder> gsonConfigCallback);  JsonMapper(Gson compact, Gson compactSensitive); String toJson(Object body); void toJson(Object body, Appendable appendable); JsonElement toJsonElement(Object body); String toJsonHtml(Object body); void toJson(Set<JsonOptions> options, Object body, Appendable appendable); T fromJson(Object json, Class<T> clazz); T fromJson(Object json, Type type); void setJsonSuppressGsonSerializationErrors(boolean suppressErrors); static GsonBuilder createDefaultGsonBuilder(EnumSet<JsonOptions> options); void toJsonHtml(Object body, Appendable appendable); long hashJson(Object body, long seed); static final String PROPERTY_JSON_SUPPRESS_GSON_SERIALIZATION_ERRORS; }