final Object typeMapping, final EntityProviderReadProperties readProperties)
throws EdmException, EntityProviderException, IOException {
if (reader.peek().equals(JsonToken.NULL)) {
reader.nextNull();
if ((readProperties == null || readProperties.isValidatingFacets()) && complexPropertyInfo.isMandatory()) {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE.addContent(complexPropertyInfo
.getName()));
}
return null;
}
reader.beginObject();
Map<String, Object> data = new HashMap<String, Object>();
Map<String, Object> mapping;
if (typeMapping != null) {
if (typeMapping instanceof Map) {
mapping = (Map<String, Object>) typeMapping;
} else {
throw new EntityProviderException(EntityProviderException.INVALID_MAPPING.addContent(complexPropertyInfo
.getName()));
}
} else {
mapping = new HashMap<String, Object>();
}
while (reader.hasNext()) {
String childName = reader.nextName();
if (FormatJson.METADATA.equals(childName)) {
reader.beginObject();
childName = reader.nextName();
if (!FormatJson.TYPE.equals(childName)) {
throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent(FormatJson.TYPE)
.addContent(FormatJson.METADATA));
}
String actualTypeName = reader.nextString();
String expectedTypeName =
complexPropertyInfo.getType().getNamespace() + Edm.DELIMITER + complexPropertyInfo.getType().getName();
if (!expectedTypeName.equals(actualTypeName)) {
throw new EntityProviderException(EntityProviderException.INVALID_ENTITYTYPE.addContent(expectedTypeName)
.addContent(actualTypeName));
}
reader.endObject();
} else {
EntityPropertyInfo childPropertyInfo = complexPropertyInfo.getPropertyInfo(childName);
if (childPropertyInfo == null) {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY.addContent(childName));
}
Object childData = readPropertyValue(reader, childPropertyInfo, mapping.get(childName), readProperties);
if (data.containsKey(childName)) {
throw new EntityProviderException(EntityProviderException.DOUBLE_PROPERTY.addContent(childName));
}
data.put(childName, childData);
}
}
reader.endObject();