Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
:ioa:
  • Loading branch information
rhysdh540 committed Aug 13, 2024
1 parent 0741fe9 commit c4178bc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/dev/nolij/zson/Zson.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,23 @@ public static Map<String, ZsonValue> obj2Map(@Nullable Object object) {

Object value = field.get(object);

if(value instanceof Map) { // also checks for null
if(value instanceof Map) {
value = obj2Map(value);
} else if(value.getClass().isArray()) {
List<Object> list = new ArrayList<>();
int length = Array.getLength(value);
for (int i = 0; i < length; i++) {
list.add(Array.get(value, i));
}
value = list;
} else if(value instanceof Iterable) {
List<Object> list = new ArrayList<>();
for (Object o : (Iterable<?>) value) {
list.add(o);
}
value = list;
} else if(value != null) {
if(value.getClass().isArray()) {
List<Object> list = new ArrayList<>();
int length = Array.getLength(value);
for (int i = 0; i < length; i++) {
list.add(Array.get(value, i));
}
value = list;
}
}

map.put(field.getName(), new ZsonValue(comment, value));
Expand Down

0 comments on commit c4178bc

Please sign in to comment.