Skip to content

Commit 014585a

Browse files
committed
Fixed error when the constructor is private
1 parent f7317ff commit 014585a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/javawebstack/abstractdata/mapper/DefaultMappers.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.javawebstack.abstractdata.mapper.exception.MapperWrongTypeException;
66
import org.javawebstack.abstractdata.util.Helpers;
77

8+
import java.lang.reflect.Constructor;
9+
import java.lang.reflect.InvocationTargetException;
810
import java.sql.Timestamp;
911
import java.text.NumberFormat;
1012
import java.text.ParseException;
@@ -303,7 +305,9 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
303305
throw new MapperException("Unmappable type '" + type.getName() + "'");
304306
AbstractObject o = element.object();
305307
try {
306-
Object obj = type.newInstance();
308+
Constructor constructor = type.getDeclaredConstructor();
309+
constructor.setAccessible(true);
310+
Object obj = constructor.newInstance();
307311
AbstractObject additional = spec.getAdditionalField() == null ? null : new AbstractObject();
308312
List<String> fieldNames = spec.getFieldSpecs().stream().map(s -> s.getField().getName()).collect(Collectors.toList());
309313
for(String k : o.keys()) {
@@ -330,7 +334,7 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
330334
if(additional != null)
331335
spec.getAdditionalField().set(obj, additional);
332336
return obj;
333-
} catch (InstantiationException | IllegalAccessException e) {
337+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
334338
throw new MapperException(e.getMessage());
335339
}
336340
}

0 commit comments

Comments
 (0)