Skip to content

Commit

Permalink
Version 0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Arraying authored and Arraying committed Jun 17, 2018
1 parent 7454547 commit 421fa72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.arraying</groupId>
<artifactId>Kotys</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
<build>
<plugins>
<plugin>
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/de/arraying/kotys/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.StringReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;

/**
* Copyright 2017 Arraying
Expand Down Expand Up @@ -258,10 +257,18 @@ public final String marshal() {
*/
@SuppressWarnings("unchecked")
public final <T> T[] marshal(Class<T> clazz) {
List<Object> objects = rawContent
.stream()
.filter(entry -> entry.getClass().equals(clazz))
.collect(Collectors.toList());
List<Object> objects = new ArrayList<>();
for(Object raw : rawContent) {
if(raw instanceof JSON) {
try {
objects.add(((JSON) raw).marshal(clazz));
} catch(Exception ignored) {}
} else {
if(raw.getClass().equals(clazz)) {
objects.add(raw);
}
}
}
Object[] array = (Object[]) Array.newInstance(clazz, objects.size());
for(int i = 0; i < array.length; i++) {
array[i] = objects.get(i);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/de/arraying/kotys/JSONORM.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ T mapTo(JSON json, String... ignoredJSONKeys)
if(rawValue instanceof JSON) {
value = ((JSON) rawValue).marshal(field.getType());
} else if(rawValue instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) rawValue;
if(jsonArray.length() == 0) {
continue;
}
Class<?> fieldType = field.getType().getComponentType();
if(fieldType.isPrimitive()) {
throw new IllegalArgumentException("Array type " + fieldType + " is primitive");
Expand Down

0 comments on commit 421fa72

Please sign in to comment.