Incorporated comments from the code review r355
This commit is contained in:
parent
05f54f3552
commit
e839336eea
@ -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.
|
||||
* By default, Gson escapes HTML characters such as < > etc. Use this option to configure
|
||||
* Gson to pass-through HTML characters as is.
|
||||
*
|
||||
* @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 setCompactPrinting(boolean escapeHtmlChars) {
|
||||
setFormatter(new JsonCompactFormatter(escapeHtmlChars));
|
||||
public GsonBuilder disableHtmlEscaping() {
|
||||
this.escapeHtmlChars = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -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 + '"'));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user