type = Primitives.box(type);
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
}
seenFields.add(new FastField(classDefiningField, attrName));
reflectionProvider.writeField(result, attrName, value, classDefiningField);
}
}
}
Map implicitCollectionsForCurrentObject = null;
while (reader.hasMoreChildren()) {
reader.moveDown();
String originalNodeName = reader.getNodeName();
Class classDefiningField = determineWhichClassDefinesField(reader);
Class fieldDeclaringClass = classDefiningField == null
? result.getClass()
: classDefiningField;
String fieldName = mapper.realMember(fieldDeclaringClass, originalNodeName);
Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper
.getImplicitCollectionDefForFieldName(fieldDeclaringClass, fieldName);
boolean fieldExistsInClass = implicitCollectionMapping == null
&& reflectionProvider.fieldDefinedInClass(fieldName, fieldDeclaringClass);
Class type = implicitCollectionMapping == null || implicitCollectionMapping.getItemType() == null
? determineType(
reader, fieldExistsInClass, result, fieldName, classDefiningField)
: implicitCollectionMapping.getItemType();
final Object value;
if (fieldExistsInClass) {
Field field = reflectionProvider.getField(classDefiningField != null ? classDefiningField : result.getClass(), fieldName);
if ((Modifier.isTransient(field.getModifiers()) && !shouldUnmarshalTransientFields())
|| !mapper.shouldSerializeMember(classDefiningField != null ? classDefiningField : result.getClass(), fieldName)) {
reader.moveUp();
continue;
}
value = unmarshallField(context, result, type, field);
// TODO the reflection provider should have returned the proper field in first place ....
Class definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField);
if (!definedType.isPrimitive()) {
type = definedType;
}
} else {
if (Map.Entry.class.equals(type)) {
reader.moveDown();
final Object key = context.convertAnother(result, HierarchicalStreams.readClassType(reader, mapper));
reader.moveUp();
reader.moveDown();
final Object v = context.convertAnother(result, HierarchicalStreams.readClassType(reader, mapper));
reader.moveUp();
value = Collections.singletonMap(key, v).entrySet().iterator().next();
} else {
value = type != null ? context.convertAnother(result, type) : null;
}
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
}
if (fieldExistsInClass) {
reflectionProvider.writeField(result, fieldName, value, classDefiningField);
seenFields.add(new FastField(classDefiningField, fieldName));
} else if (type != null) {
implicitCollectionsForCurrentObject = writeValueToImplicitCollection(context, value, implicitCollectionsForCurrentObject, result, originalNodeName);
}
reader.moveUp();