Skip to content

Commit dfef0dd

Browse files
committed
fix: #45 Error casting collection at response resource
1 parent 51223ff commit dfef0dd

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![ditiow](docs/assets/logo.png)
22

3-
[ ![Download](https://api.bintray.com/packages/marcosvidolin/maven/ditiow/images/download.svg?version=1.1.0) ](https://bintray.com/marcosvidolin/maven/ditiow/1.0.0/link) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f79c15a8aa44706afcf49261c1a6ef1)](https://www.codacy.com/manual/marcosvidolin/ditiow?utm_source=github.com&utm_medium=referral&utm_content=marcosvidolin/ditiow&utm_campaign=Badge_Grade) ![Build](https://github.com/marcosvidolin/ditiow/workflows/Java%20CI%20with%20Gradle/badge.svg?branch=master)
3+
[ ![Download](https://api.bintray.com/packages/marcosvidolin/maven/ditiow/images/download.svg?version=1.2.0) ](https://bintray.com/marcosvidolin/maven/ditiow/1.2.0/link) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f79c15a8aa44706afcf49261c1a6ef1)](https://www.codacy.com/manual/marcosvidolin/ditiow?utm_source=github.com&utm_medium=referral&utm_content=marcosvidolin/ditiow&utm_campaign=Badge_Grade) ![Build](https://github.com/marcosvidolin/ditiow/workflows/Java%20CI%20with%20Gradle/badge.svg?branch=master)
44

55
Ditiow is an aspect library designed to help you safely expose features of your Spring REST API without having to expose data from the persistence or business layer of your application.
66

@@ -13,7 +13,7 @@ Ditiow is an aspect library designed to help you safely expose features of your
1313
- Gradle
1414

1515
```groovy
16-
compile 'com.vidolima:ditiow:1.1.0'
16+
compile 'com.vidolima:ditiow:1.2.0'
1717
```
1818
1919
- Maven
@@ -22,7 +22,7 @@ Ditiow is an aspect library designed to help you safely expose features of your
2222
<dependency>
2323
<groupId>com.vidolima</groupId>
2424
<artifactId>ditiow</artifactId>
25-
<version>1.1.0</version>
25+
<version>1.2.0</version>
2626
<type>pom</type>
2727
</dependency>
2828
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ buildscript {
22
ext.projectName = 'ditiow'
33
ext.projectGroup = 'com.vidolima'
44
ext.projectArtifact = 'ditiow'
5-
ext.projectVersion = '1.1.0'
5+
ext.projectVersion = '1.2.0'
66

77
repositories {
88
mavenCentral()

src/main/java/com/vidolima/ditiow/assembler/AbstractAssembler.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.lang.reflect.Field;
1010
import java.lang.reflect.InvocationTargetException;
11+
import java.util.ArrayList;
1112
import java.util.Collection;
1213

1314
/**
@@ -54,7 +55,7 @@ protected <T> T createCopy(final Object obj, final Class<T> classOfTargetObject
5455
}
5556

5657
if (obj instanceof Collection<?>) {
57-
return (T) createCollectionCopy((Collection<?>) obj, classOfTargetObject);
58+
return (T) createCollectionCopy((Collection<?>) obj, classOfTargetObject, ignoreProperties);
5859
}
5960

6061
try {
@@ -67,7 +68,6 @@ protected <T> T createCopy(final Object obj, final Class<T> classOfTargetObject
6768
}
6869
}
6970

70-
7171
/**
7272
* Return a new object (instance of "T") with all values copied from the the given object.
7373
*
@@ -85,22 +85,35 @@ protected <T> T createCopy(final Object obj, final Class<T> classOfTargetObject)
8585
*
8686
* @param objs object to be copied
8787
* @param classOfTargetObject the class of the target object
88+
* @param ignoreProperties properties to be ignored
8889
* @param <T> return type
8990
* @return T
9091
*/
91-
protected <T> Collection<T> createCollectionCopy(Collection<?> objs, final Class<T> classOfTargetObject) {
92+
protected <T> Collection<T> createCollectionCopy(Collection<?> objs, final Class<T> classOfTargetObject
93+
, final String[] ignoreProperties) {
94+
9295
if (objs == null) {
9396
return null;
9497
}
95-
Collection<T> targetObject;
96-
try {
97-
targetObject = (Collection<T>) classOfTargetObject.newInstance();
98-
} catch (InstantiationException | IllegalAccessException e) {
99-
throw new IllegalCopyException("Could not create new instance of the target class.", e);
100-
}
98+
99+
Collection<T> targetObject = new ArrayList<>();
100+
101101
for (Object obj : objs) {
102-
targetObject.add(this.assembly(obj, classOfTargetObject));
102+
targetObject.add(this.assembly(obj, classOfTargetObject, ignoreProperties));
103103
}
104104
return targetObject;
105105
}
106+
107+
/**
108+
* Return a new object (instance of "T") with all values copied from the the given object.
109+
*
110+
* @param objs object to be copied
111+
* @param classOfTargetObject the class of the target object
112+
* @param <T> return type
113+
* @return T
114+
*/
115+
protected <T> Collection<T> createCollectionCopy(Collection<?> objs, final Class<T> classOfTargetObject) {
116+
return this.createCollectionCopy(objs, classOfTargetObject, null);
117+
}
118+
106119
}

0 commit comments

Comments
 (0)