From e839336eea7aa7e414108a6d33703349adc7a705 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 30 Dec 2008 19:03:43 +0000 Subject: [PATCH] Incorporated comments from the code review r355 --- .../java/com/google/gson/GsonBuilder.java | 25 ++++++------------- .../google/gson/functional/PrimitiveTest.java | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index 3b4354c1..a57eae9f 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -68,6 +68,7 @@ public final class GsonBuilder { private int dateStyle; private int timeStyle; private boolean serializeSpecialFloatingPointValues; + private boolean escapeHtmlChars; /** * Creates a GsonBuilder instance that can be used to build Gson with various configuration @@ -80,6 +81,7 @@ public final class GsonBuilder { ignoreVersionsAfter = VersionConstants.IGNORE_VERSIONS; serializeLongAsString = false; serializeInnerClasses = true; + escapeHtmlChars = true; anonAndLocalClassExclusionStrategy = new AnonymousAndLocalClassExclusionStrategy(); innerClassExclusionStrategy = new InnerClassExclusionStrategy(); modifierBasedExclusionStrategy = Gson.DEFAULT_MODIFIER_BASED_EXCLUSION_STRATEGY; @@ -202,32 +204,19 @@ public final class GsonBuilder { * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern */ public GsonBuilder setPrettyPrinting() { - setFormatter(new JsonPrintFormatter()); - return this; - } - - /** - * Configures Gson to output Json that fits in a page for pretty printing. This option only - * affects Json serialization. - * - * @param escapeHtmlChars true if specific HTML characters should be escaped - * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern - * @since 1.3 - */ - public GsonBuilder setPrettyPrinting(boolean escapeHtmlChars) { setFormatter(new JsonPrintFormatter(escapeHtmlChars)); return this; } /** - * Configures Gson to output Json in a compact format. - * - * @param escapeHtmlChars true if specific HTML characters should be escaped + * By default, Gson escapes HTML characters such as < > etc. Use this option to configure + * Gson to pass-through HTML characters as is. + * * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern * @since 1.3 */ - public GsonBuilder setCompactPrinting(boolean escapeHtmlChars) { - setFormatter(new JsonCompactFormatter(escapeHtmlChars)); + public GsonBuilder disableHtmlEscaping() { + this.escapeHtmlChars = false; return this; } diff --git a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java index 74e2dfd2..6d24d092 100644 --- a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java +++ b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java @@ -553,7 +553,7 @@ public class PrimitiveTest extends TestCase { String result = gson.toJson(target); assertFalse(result.equals('"' + target + '"')); - gson = new GsonBuilder().setCompactPrinting(false).create(); + gson = new GsonBuilder().disableHtmlEscaping().create(); result = gson.toJson(target); assertTrue(result.equals('"' + target + '"')); }