Skip to content

Commit 59a4a3d

Browse files
committed
Clear collections before pouring in json data. Fixes #75
1 parent d85faf1 commit 59a4a3d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ apply plugin: "signing";
2323

2424
group = "blue.endless";
2525
archivesBaseName = "Jankson";
26-
version = "1.2.2";
26+
version = "1.2.3";
2727

2828
sourceCompatibility = 1.8;
2929
targetCompatibility = 1.8;

src/main/java/blue/endless/jankson/impl/POJODeserializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ private static boolean isCollections(Class<?> clazz) {
218218
public static void unpackMap(Map<Object, Object> map, Type keyType, Type valueType, JsonElement elem, blue.endless.jankson.api.Marshaller marshaller) throws DeserializationException {
219219
if (!(elem instanceof JsonObject)) throw new DeserializationException("Cannot deserialize a "+elem.getClass().getSimpleName()+" into a Map - expected a JsonObject!");
220220

221-
//Class<?> keyClass = TypeMagic.classForType(keyType);
222-
//Class<?> valueClass = TypeMagic.classForType(valueType);
221+
map.clear(); //This may be a user-supplied collection, initialized in the constructor with default mappings. Erase those.
222+
223223
JsonObject object = (JsonObject)elem;
224224
for(Map.Entry<String, JsonElement> entry : object.entrySet()) {
225225
try {
@@ -233,6 +233,8 @@ public static void unpackMap(Map<Object, Object> map, Type keyType, Type valueTy
233233
public static void unpackCollection(Collection<Object> collection, Type elementType, JsonElement elem, blue.endless.jankson.api.Marshaller marshaller) throws DeserializationException {
234234
if (!(elem instanceof JsonArray)) throw new DeserializationException("Cannot deserialize a "+elem.getClass().getSimpleName()+" into a Set - expected a JsonArray!");
235235

236+
collection.clear(); //This may be a user-supplied collection, initialized in the constructor with default items. Erase those.
237+
236238
JsonArray array = (JsonArray)elem;
237239
for(JsonElement arrayElem : array) {
238240

0 commit comments

Comments
 (0)