Minor clean-up in Gson class.
This commit is contained in:
parent
fb7bd7b1b7
commit
56aa828350
@ -78,8 +78,6 @@ public final class Gson {
|
|||||||
//TODO(inder): get rid of all the registerXXX methods and take all such parameters in the
|
//TODO(inder): get rid of all the registerXXX methods and take all such parameters in the
|
||||||
// constructor instead. At the minimum, mark those methods private.
|
// constructor instead. At the minimum, mark those methods private.
|
||||||
|
|
||||||
private static final String NULL_STRING = "null";
|
|
||||||
|
|
||||||
static final boolean DEFAULT_JSON_NON_EXECUTABLE = false;
|
static final boolean DEFAULT_JSON_NON_EXECUTABLE = false;
|
||||||
|
|
||||||
// Default instances of plug-ins
|
// Default instances of plug-ins
|
||||||
@ -240,7 +238,7 @@ public final class Gson {
|
|||||||
*/
|
*/
|
||||||
public String toJson(Object src) {
|
public String toJson(Object src) {
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
return serializeNulls ? NULL_STRING : "";
|
return toJson(JsonNull.createJsonNull());
|
||||||
}
|
}
|
||||||
return toJson(src, src.getClass());
|
return toJson(src, src.getClass());
|
||||||
}
|
}
|
||||||
@ -281,14 +279,10 @@ public final class Gson {
|
|||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public void toJson(Object src, Appendable writer) throws JsonIOException {
|
public void toJson(Object src, Appendable writer) throws JsonIOException {
|
||||||
try {
|
if (src != null) {
|
||||||
if (src != null) {
|
toJson(src, src.getClass(), writer);
|
||||||
toJson(src, src.getClass(), writer);
|
} else {
|
||||||
} else if (serializeNulls) {
|
toJson(JsonNull.createJsonNull(), writer);
|
||||||
writeOutNullString(writer);
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
throw new RuntimeException(ioe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,15 +555,6 @@ public final class Gson {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends the {@link #NULL_STRING} to the {@code writer} object.
|
|
||||||
*
|
|
||||||
* @param writer the object to append the null value to
|
|
||||||
*/
|
|
||||||
private void writeOutNullString(Appendable writer) throws IOException {
|
|
||||||
writer.append(NULL_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder("{")
|
StringBuilder sb = new StringBuilder("{")
|
||||||
|
Loading…
Reference in New Issue
Block a user