You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2016/09/16 07:47:09 UTC
svn commit: r1761008 - in /felix/trunk/converter/converter/src:
main/java/org/apache/felix/converter/impl/ConvertingImpl.java
test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
Author: davidb
Date: Fri Sep 16 07:47:09 2016
New Revision: 1761008
URL: http://svn.apache.org/viewvc?rev=1761008&view=rev
Log:
FELIX-5341 Exception thrown when field in Map missing from DTO
Includes a test case.
Modified:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1761008&r1=1761007&r2=1761008&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java Fri Sep 16 07:47:09 2016
@@ -228,7 +228,11 @@ public class ConvertingImpl implements C
try {
f = targetCls.getDeclaredField(entry.getKey().toString());
} catch (NoSuchFieldException e) {
- f = targetCls.getField(entry.getKey().toString());
+ try {
+ f = targetCls.getField(entry.getKey().toString());
+ } catch (NoSuchFieldException e1) {
+ // There is not field with this name
+ }
}
if (f != null) {
@@ -546,6 +550,7 @@ public class ConvertingImpl implements C
cls.getConstructor();
return cls; // If no exception the constructor is there
} catch (NoSuchMethodException e1) {
+ // There is no constructor with this name
}
}
for (Class<?> intf : cls.getInterfaces()) {
Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java?rev=1761008&r1=1761007&r2=1761008&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java (original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java Fri Sep 16 07:47:09 2016
@@ -508,6 +508,14 @@ public class ConverterServiceTest {
// TODO convert back
}
+ @Test
+ public void testMapToDTOWithSurplusMapFiels() {
+ Map<String, String> m = new HashMap<>();
+ m.put("foo", "bar");
+ MyDTO3 dtoDoesNotMap = converter.convert(m).to(MyDTO3.class);
+ assertNull(dtoDoesNotMap.charSet);
+ }
+
@Test @SuppressWarnings("rawtypes")
public void testCopyMap() {
Map m = new HashMap();