Code review changes from r476

This commit is contained in:
Inderjeet Singh 2009-10-08 23:23:52 +00:00
parent 93b0008486
commit 2bddd575b3
5 changed files with 10 additions and 6 deletions

View File

@ -69,7 +69,7 @@ abstract class JsonDeserializationVisitor<T> implements ObjectNavigator.Visitor
Type objType = objTypePair.getType();
JsonDeserializer deserializer = deserializers.getHandlerFor(objType);
if (deserializer != null) {
if (json != null && !json.isJsonNull()) {
if (!json.isJsonNull()) {
target = (T) deserializer.deserialize(json, objType, context);
}
return true;

View File

@ -112,7 +112,7 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
@SuppressWarnings("unchecked")
JsonDeserializer deserializer = deserializers.getHandlerFor(actualTypeOfField);
if (deserializer != null) {
if (child != null && !child.isJsonNull()) {
if (!child.isJsonNull()) {
Object value = deserializer.deserialize(child, actualTypeOfField, context);
f.set(parent, value);
}

View File

@ -32,7 +32,7 @@ import java.util.NoSuchElementException;
* <pre>
* JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
* JsonElement element;
* synchronized (someCommonObject) {
* synchronized (parser) { // synchronize on an object shared by threads
* if (parser.hasNext()) {
* element = parser.next();
* }

View File

@ -34,7 +34,7 @@ final class JsonTreeNavigator {
}
public void navigate(JsonElement element) throws IOException {
if (element == null || element.isJsonNull()) {
if (element.isJsonNull()) {
visitor.visitNull();
} else if (element.isJsonArray()) {
JsonArray array = element.getAsJsonArray();
@ -68,7 +68,7 @@ final class JsonTreeNavigator {
*/
private boolean visitChild(JsonObject parent, String childName, JsonElement child,
boolean isFirst) throws IOException {
if (child == null || child.isJsonNull()) {
if (child.isJsonNull()) {
if (visitNulls) {
visitor.visitNullObjectMember(parent, childName, isFirst);
navigate(child.getAsJsonNull());
@ -93,7 +93,7 @@ final class JsonTreeNavigator {
* Returns true if the child was visited, false if it was skipped.
*/
private void visitChild(JsonArray parent, JsonElement child, boolean isFirst) throws IOException {
if (child == null || child.isJsonNull()) {
if (child.isJsonNull()) {
visitor.visitNullArrayMember(parent, isFirst);
navigate(child);
} else if (child.isJsonArray()) {

View File

@ -119,9 +119,11 @@ public class CustomDeserializerTest extends TestCase {
SubType1 target = (SubType1) gson.fromJson(json, MyBase.class);
assertEquals("abc", target.field1);
}
private static class MyBase {
static final String TYPE_ACCESS = "__type__";
}
private enum SubTypes {
SUB_TYPE1(SubType1.class),
SUB_TYPE2(SubType2.class);
@ -133,9 +135,11 @@ public class CustomDeserializerTest extends TestCase {
return subClass;
}
}
private static class SubType1 extends MyBase {
String field1;
}
private static class SubType2 extends MyBase {
@SuppressWarnings("unused")
String field2;