Code review changes from r476
This commit is contained in:
parent
93b0008486
commit
2bddd575b3
@ -69,7 +69,7 @@ abstract class JsonDeserializationVisitor<T> implements ObjectNavigator.Visitor
|
|||||||
Type objType = objTypePair.getType();
|
Type objType = objTypePair.getType();
|
||||||
JsonDeserializer deserializer = deserializers.getHandlerFor(objType);
|
JsonDeserializer deserializer = deserializers.getHandlerFor(objType);
|
||||||
if (deserializer != null) {
|
if (deserializer != null) {
|
||||||
if (json != null && !json.isJsonNull()) {
|
if (!json.isJsonNull()) {
|
||||||
target = (T) deserializer.deserialize(json, objType, context);
|
target = (T) deserializer.deserialize(json, objType, context);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -112,7 +112,7 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
JsonDeserializer deserializer = deserializers.getHandlerFor(actualTypeOfField);
|
JsonDeserializer deserializer = deserializers.getHandlerFor(actualTypeOfField);
|
||||||
if (deserializer != null) {
|
if (deserializer != null) {
|
||||||
if (child != null && !child.isJsonNull()) {
|
if (!child.isJsonNull()) {
|
||||||
Object value = deserializer.deserialize(child, actualTypeOfField, context);
|
Object value = deserializer.deserialize(child, actualTypeOfField, context);
|
||||||
f.set(parent, value);
|
f.set(parent, value);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import java.util.NoSuchElementException;
|
|||||||
* <pre>
|
* <pre>
|
||||||
* JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
|
* JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
|
||||||
* JsonElement element;
|
* JsonElement element;
|
||||||
* synchronized (someCommonObject) {
|
* synchronized (parser) { // synchronize on an object shared by threads
|
||||||
* if (parser.hasNext()) {
|
* if (parser.hasNext()) {
|
||||||
* element = parser.next();
|
* element = parser.next();
|
||||||
* }
|
* }
|
||||||
|
@ -34,7 +34,7 @@ final class JsonTreeNavigator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void navigate(JsonElement element) throws IOException {
|
public void navigate(JsonElement element) throws IOException {
|
||||||
if (element == null || element.isJsonNull()) {
|
if (element.isJsonNull()) {
|
||||||
visitor.visitNull();
|
visitor.visitNull();
|
||||||
} else if (element.isJsonArray()) {
|
} else if (element.isJsonArray()) {
|
||||||
JsonArray array = element.getAsJsonArray();
|
JsonArray array = element.getAsJsonArray();
|
||||||
@ -68,7 +68,7 @@ final class JsonTreeNavigator {
|
|||||||
*/
|
*/
|
||||||
private boolean visitChild(JsonObject parent, String childName, JsonElement child,
|
private boolean visitChild(JsonObject parent, String childName, JsonElement child,
|
||||||
boolean isFirst) throws IOException {
|
boolean isFirst) throws IOException {
|
||||||
if (child == null || child.isJsonNull()) {
|
if (child.isJsonNull()) {
|
||||||
if (visitNulls) {
|
if (visitNulls) {
|
||||||
visitor.visitNullObjectMember(parent, childName, isFirst);
|
visitor.visitNullObjectMember(parent, childName, isFirst);
|
||||||
navigate(child.getAsJsonNull());
|
navigate(child.getAsJsonNull());
|
||||||
@ -93,7 +93,7 @@ final class JsonTreeNavigator {
|
|||||||
* Returns true if the child was visited, false if it was skipped.
|
* Returns true if the child was visited, false if it was skipped.
|
||||||
*/
|
*/
|
||||||
private void visitChild(JsonArray parent, JsonElement child, boolean isFirst) throws IOException {
|
private void visitChild(JsonArray parent, JsonElement child, boolean isFirst) throws IOException {
|
||||||
if (child == null || child.isJsonNull()) {
|
if (child.isJsonNull()) {
|
||||||
visitor.visitNullArrayMember(parent, isFirst);
|
visitor.visitNullArrayMember(parent, isFirst);
|
||||||
navigate(child);
|
navigate(child);
|
||||||
} else if (child.isJsonArray()) {
|
} else if (child.isJsonArray()) {
|
||||||
|
@ -119,9 +119,11 @@ public class CustomDeserializerTest extends TestCase {
|
|||||||
SubType1 target = (SubType1) gson.fromJson(json, MyBase.class);
|
SubType1 target = (SubType1) gson.fromJson(json, MyBase.class);
|
||||||
assertEquals("abc", target.field1);
|
assertEquals("abc", target.field1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyBase {
|
private static class MyBase {
|
||||||
static final String TYPE_ACCESS = "__type__";
|
static final String TYPE_ACCESS = "__type__";
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum SubTypes {
|
private enum SubTypes {
|
||||||
SUB_TYPE1(SubType1.class),
|
SUB_TYPE1(SubType1.class),
|
||||||
SUB_TYPE2(SubType2.class);
|
SUB_TYPE2(SubType2.class);
|
||||||
@ -133,9 +135,11 @@ public class CustomDeserializerTest extends TestCase {
|
|||||||
return subClass;
|
return subClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SubType1 extends MyBase {
|
private static class SubType1 extends MyBase {
|
||||||
String field1;
|
String field1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SubType2 extends MyBase {
|
private static class SubType2 extends MyBase {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
String field2;
|
String field2;
|
||||||
|
Loading…
Reference in New Issue
Block a user