in odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonPropertyConsumer.java [179:245]
private Object readSimpleProperty(final JsonReader reader, final EntityPropertyInfo entityPropertyInfo,
final Object typeMapping, final EntityProviderReadProperties readProperties)
throws EdmException, EntityProviderException, IOException {
final EdmSimpleType type = (EdmSimpleType) entityPropertyInfo.getType();
Object value = null;
final JsonToken tokenType = reader.peek();
if (tokenType == JsonToken.NULL) {
reader.nextNull();
} else {
switch (EdmSimpleTypeKind.valueOf(type.getName())) {
case Boolean:
if (tokenType == JsonToken.BOOLEAN) {
value = reader.nextBoolean();
value = value.toString();
} else {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE
.addContent(entityPropertyInfo.getName()));
}
break;
case Byte:
case SByte:
case Int16:
case Int32:
if (tokenType == JsonToken.NUMBER) {
value = reader.nextInt();
value = value.toString();
} else {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE
.addContent(entityPropertyInfo.getName()));
}
break;
case Single:
case Double:
if (tokenType == JsonToken.STRING) {
value = reader.nextString();
} else if (tokenType == JsonToken.NUMBER) {
value = reader.nextDouble();
value = value.toString();
} else {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE
.addContent(entityPropertyInfo.getName()));
}
break;
case Decimal:
if (tokenType == JsonToken.NUMBER || tokenType == JsonToken.STRING) {
value = reader.nextString();
} else {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE
.addContent(entityPropertyInfo.getName()));
}
break;
default:
if (tokenType == JsonToken.STRING) {
value = reader.nextString();
} else {
throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE
.addContent(entityPropertyInfo.getName()));
}
break;
}
}
final Class<?> typeMappingClass = typeMapping == null ? type.getDefaultType() : (Class<?>) typeMapping;
final EdmFacets facets = readProperties == null || readProperties.isValidatingFacets() ?
entityPropertyInfo.getFacets() : null;
return type.valueOfString((String) value, EdmLiteralKind.JSON, facets, typeMappingClass);
}