提交 634693b2 编写于 作者: K Kohsuke Kawaguchi

attempt to unmarshal to a totally incompatible type should result in a failure.

This is actually what I was expecting, as evident in the javadoc of XmlFile.unmarshal()
上级 087993bc
...@@ -322,14 +322,15 @@ public class RobustReflectionConverter implements Converter { ...@@ -322,14 +322,15 @@ public class RobustReflectionConverter implements Converter {
protected Object instantiateNewInstance(HierarchicalStreamReader reader, UnmarshallingContext context) { protected Object instantiateNewInstance(HierarchicalStreamReader reader, UnmarshallingContext context) {
String readResolveValue = reader.getAttribute(mapper.aliasForAttribute("resolves-to")); String readResolveValue = reader.getAttribute(mapper.aliasForAttribute("resolves-to"));
Class type = readResolveValue != null ? mapper.realClass(readResolveValue) : context.getRequiredType();
Object currentObject = context.currentObject(); Object currentObject = context.currentObject();
if (currentObject != null) { if (currentObject != null) {
return currentObject; if (type.isInstance(currentObject))
} else if (readResolveValue != null) { return currentObject;
return reflectionProvider.newInstance(mapper.realClass(readResolveValue));
} else {
return reflectionProvider.newInstance(context.getRequiredType());
} }
return reflectionProvider.newInstance(type);
} }
private static class SeenFields { private static class SeenFields {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册