throw exception;
}
reflectionProvider.writeField(result, fieldName, value, declaringClass);
if (!seenFields.add(new FastField(declaringClass, fieldName))) {
throw new DuplicateFieldException(fieldName
+ " ["
+ declaringClass.getName()
+ "]");
}
}
}
}
if (valueField != null) {
final Class classDefiningField = valueField.getDeclaringClass();
final String fieldName = valueField.getName();
if (fieldName == null
|| !reflectionProvider.fieldDefinedInClass(fieldName, resultType)) {
final ConversionException exception = new ConversionException(
"Cannot assign value to field of type");
exception.add("element", reader.getNodeName());
exception.add("field", fieldName);
exception.add("target type", context.getRequiredType().getName());
throw exception;
}
Class type;
final String classAttribute = HierarchicalStreams
.readClassAttribute(reader, mapper);
if (classAttribute != null) {
type = mapper.realClass(classAttribute);
} else {
type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(
result, fieldName, classDefiningField));
}
final Field field = reflectionProvider.getField(classDefiningField, fieldName);
final Object value = context.convertAnother(
result, type,
mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
final Class definedType = reflectionProvider.getFieldType(
result, fieldName, classDefiningField);
if (!definedType.isPrimitive()) {
type = definedType;
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
final ConversionException exception = new ConversionException(
"Cannot assign object to type");
exception.add("object type", value.getClass().getName());
exception.add("target type", type.getName());
throw exception;
}
reflectionProvider.writeField(result, fieldName, value, classDefiningField);
if (!seenFields.add(new FastField(classDefiningField, fieldName))) {
throw new DuplicateFieldException(fieldName
+ " ["
+ classDefiningField.getName()
+ "]");
}
}