fix for bug 56 where Gson wasn't serialization null fields of type string,
collection and arrays properly even when serializeNulls was set.
This commit is contained in:
parent
d61e754fb6
commit
cdd5163458
@ -80,14 +80,22 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
||||
}
|
||||
|
||||
public void visitArrayField(Field f, Type typeOfF, Object obj) {
|
||||
if (!isFieldNull(f, obj)) {
|
||||
if (isFieldNull(f, obj)) {
|
||||
if (serializeNulls) {
|
||||
addChildAsElement(f, new JsonNull());
|
||||
}
|
||||
} else {
|
||||
Object array = getFieldValue(f, obj);
|
||||
addAsChildOfObject(f, typeOfF, array);
|
||||
}
|
||||
}
|
||||
|
||||
public void visitCollectionField(Field f, Type typeOfF, Object obj) {
|
||||
if (!isFieldNull(f, obj)) {
|
||||
if (isFieldNull(f, obj)) {
|
||||
if (serializeNulls) {
|
||||
addChildAsElement(f, new JsonNull());
|
||||
}
|
||||
} else {
|
||||
if (typeOfF == null) {
|
||||
throw new RuntimeException("Can not handle non-generic collections");
|
||||
}
|
||||
@ -152,7 +160,11 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
||||
}
|
||||
|
||||
public void visitPrimitiveField(Field f, Type typeOfF, Object obj) {
|
||||
if (!isFieldNull(f, obj)) {
|
||||
if (isFieldNull(f, obj)) {
|
||||
if (serializeNulls) {
|
||||
addChildAsElement(f, new JsonNull());
|
||||
}
|
||||
} else {
|
||||
TypeInfo typeInfo = new TypeInfo(typeOfF);
|
||||
if (typeInfo.isPrimitiveOrStringAndNotAnArray()) {
|
||||
Object fieldValue = getFieldValue(f, obj);
|
||||
|
Loading…
Reference in New Issue
Block a user