Gson deserialization: return JsonNull object when object list is empty.

This commit is contained in:
alena 2010-11-22 14:56:25 -08:00
parent a646745516
commit b7eefe1836
1 changed files with 7 additions and 0 deletions

View File

@ -53,6 +53,10 @@ public class SecStorageFirewallCfgCommand extends Command {
}
public JsonElement serialize(List<PortConfig> src, Type typeOfSrc, JsonSerializationContext context) {
if (src.size() == 0) {
s_logger.info("Returning JsonNull");
return new JsonNull();
}
Gson json = s_gBuilder.create();
s_logger.debug("Returning gson tree");
return json.toJsonTree(src, listType);
@ -60,6 +64,9 @@ public class SecStorageFirewallCfgCommand extends Command {
public List<PortConfig> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
if (json.isJsonNull()) {
return new ArrayList<PortConfig>();
}
Gson jsonp = s_gBuilder.create();
List<PortConfig> pcs = jsonp.fromJson(json, listType);
return pcs;