Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
Fixed a migrating bug with null values.
  • Loading branch information
LemmoTresto committed Aug 10, 2019
1 parent ccddd3a commit fe58724
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

<groupId>me.max</groupId>
<artifactId>migrational</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>

<name>Migrational</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/me/max/migrational/Migrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -167,8 +169,11 @@ public Map<String, Object> 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.
Expand Down

0 comments on commit fe58724

Please sign in to comment.