From fe5872420bb3e913ede8bbb1316d6604e39637eb Mon Sep 17 00:00:00 2001 From: Max Berkelmans Date: Sat, 10 Aug 2019 12:37:53 +0200 Subject: [PATCH] v1.1.1 Fixed a migrating bug with null values. --- pom.xml | 6 +++++- src/main/java/me/max/migrational/Migrator.java | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 2d89cdc..2a6d783 100644 --- a/pom.xml +++ b/pom.xml @@ -24,10 +24,14 @@ me.max migrational - 1.1.0 + 1.1.1 Migrational + + UTF-8 + + Apache License, Version 2.0 diff --git a/src/main/java/me/max/migrational/Migrator.java b/src/main/java/me/max/migrational/Migrator.java index df0eead..f5d7d6d 100644 --- a/src/main/java/me/max/migrational/Migrator.java +++ b/src/main/java/me/max/migrational/Migrator.java @@ -130,7 +130,7 @@ public Migrator(Class clazz) { public Object migrateToClass() throws IllegalAccessException, InvocationTargetException, InstantiationException { //Check if the constructor is null due to not being found on instantiation if (constructor == null) - throw new InvalidConstructorException("Constructor provided was null, no matching constructor was found on instantiation make sure to set one.", constructor); + throw new InvalidConstructorException("Constructor provided was null, no matching constructor was found on instantiation make sure to set one.", null); //Create a new instance of the object lastMigratedObject = constructor.newInstance(); @@ -140,7 +140,9 @@ public Object migrateToClass() throws IllegalAccessException, InvocationTargetEx Migratable migratable = getAnnotationFromField(field); //Get the annotation //Get correct key String key = (migratable.key().isEmpty()) ? field.getName() : migratable.key(); - field.set(lastMigratedObject, migratedMap.get(key)); + Object val = migratedMap.get(key); + if (val == null) continue; + field.set(lastMigratedObject, val); } return lastMigratedObject; @@ -167,8 +169,11 @@ public Map migrateToMap() { migratedMap.put(key, data.get(key)); continue; } + + if (migratable.defaultValue().isEmpty()) continue; + //It does not, so let's set the default value - migratedMap.put(key, migratable.defaultValue().isEmpty() ? data.get(key) : migratable.defaultValue()); + migratedMap.put(key, migratable.defaultValue()); } //Return the migrated map.