diff --git a/core/src/main/java/hudson/util/RobustReflectionConverter.java b/core/src/main/java/hudson/util/RobustReflectionConverter.java
index 4192ea7b53..96b10f6ef9 100644
--- a/core/src/main/java/hudson/util/RobustReflectionConverter.java
+++ b/core/src/main/java/hudson/util/RobustReflectionConverter.java
@@ -506,9 +506,9 @@ public class RobustReflectionConverter implements Converter {
private Class determineType(HierarchicalStreamReader reader, boolean validField, Object result, String fieldName, Class definedInCls) {
String classAttribute = reader.getAttribute(mapper.aliasForAttribute("class"));
- Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls);
if (classAttribute != null) {
Class specifiedType = mapper.realClass(classAttribute);
+ Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls);
if(fieldType.isAssignableFrom(specifiedType))
// make sure that the specified type in XML is compatible with the field type.
// this allows the code to evolve in more flexible way.
@@ -522,6 +522,7 @@ public class RobustReflectionConverter implements Converter {
return mapper.realClass(reader.getNodeName());
}
} else {
+ Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls);
return mapper.defaultImplementationOf(fieldType);
}
}
diff --git a/core/src/test/java/hudson/util/RobustReflectionConverterTest.java b/core/src/test/java/hudson/util/RobustReflectionConverterTest.java
index 08c34df29d..2ef437512a 100644
--- a/core/src/test/java/hudson/util/RobustReflectionConverterTest.java
+++ b/core/src/test/java/hudson/util/RobustReflectionConverterTest.java
@@ -32,8 +32,10 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.ConversionException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.hamcrest.Matchers;
import org.junit.Test;
/**
@@ -100,6 +102,23 @@ public class RobustReflectionConverterTest {
assertEquals(Billy.class, s.lover.getClass());
}
+ @Test
+ public void implicitCollection() {
+ XStream2 xs = new XStream2();
+ xs.alias("hold", Hold.class);
+ xs.addImplicitCollection(Hold.class,"items", "item", String.class);
+ Hold h = (Hold) xs.fromXML("- a
- b
");
+ assertThat(h.items, Matchers.containsInAnyOrder("a", "b"));
+ assertEquals("\n" +
+ " - a
\n" +
+ " - b
\n" +
+ "", xs.toXML(h));
+ }
+
+ public static class Hold {
+ List items;
+ }
+
@Retention(RetentionPolicy.RUNTIME) @interface Owner {String value();}
public static class Projekt {
Bild[] bildz;