Skip to content

Commit

Permalink
hopefully fixed random new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
DenuxPlays committed Jul 31, 2023
1 parent ba0faac commit f60837f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '17', '20' ]
java: [ '11', '17', '20' ]

steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/dev/denux/dtp/internal/writer/TomlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import dev.denux.dtp.util.PrimitiveUtil;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -36,19 +38,23 @@ public String writeToString() {
Map<Class<?>, Field> subClasses = new HashMap<>();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if (Modifier.isStatic(field.getModifiers()))
continue;
try {
field.setAccessible(true);
Class<?> clazz = PrimitiveUtil.wrap(field.getType());
Object fieldObj = field.get(object);
if (fieldObj == null) {
try {
fieldObj = clazz.newInstance();
clazz.getConstructor().newInstance();
} catch (InstantiationException exception) {
throw new TomlWriteException(String.format("Due to the value of %s " +
"being null we tried to create a new instance of %s but this also" +
"failed. Skipping field.", field.getName(), clazz.getSimpleName()));
}
}
} catch (InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
if (String.class.equals(clazz)) {
handleString(field, fieldObj, builder);
} else if (Number.class.isAssignableFrom(clazz)) {
Expand Down

0 comments on commit f60837f

Please sign in to comment.