Default to empty if map is empty in serializer

This commit is contained in:
libraryaddict 2019-09-15 12:26:29 +12:00
parent d849041604
commit 80b11bfc6a

View File

@ -105,8 +105,17 @@ public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, Jso
if (opt instanceof ParameterizedType) { if (opt instanceof ParameterizedType) {
Type val = ((ParameterizedType) opt).getActualTypeArguments()[0]; Type val = ((ParameterizedType) opt).getActualTypeArguments()[0];
entry.setValue(Optional.of( Optional value;
gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")), val)));
if (((LinkedTreeMap) entry.getValue()).isEmpty()) {
value = Optional.empty();
} else {
value = Optional
.of(gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")),
val));
}
entry.setValue(value);
} }
} }
} }