private Object readPrimitiveValue(final String name, final EdmPrimitiveType type, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { if (isValidNull(name, isNullable, jsonNode)) { return null; } final boolean isGeoType = type.getName().startsWith("Geo"); if (!isGeoType) { checkForValueNode(name, jsonNode); } checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode); try { if (isGeoType) { return readPrimitiveGeoValue(name, type, (ObjectNode) jsonNode); } return type.valueOfString(jsonNode.asText(), isNullable, maxLength, precision, scale, isUnicode, getJavaClassForPrimitiveType(mapping, type)); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value: " + jsonNode.asText() + " for property: " + name, e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); } }
private Object readPrimitiveValue(final String name, final EdmPrimitiveType type, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { if (isValidNull(name, isNullable, jsonNode)) { return null; } final boolean isGeoType = type.getName().startsWith("Geo"); if (!isGeoType) { checkForValueNode(name, jsonNode); } checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode); try { if (isGeoType) { return readPrimitiveGeoValue(name, type, (ObjectNode) jsonNode); } return type.valueOfString(jsonNode.asText(), isNullable, maxLength, precision, scale, isUnicode, getJavaClassForPrimitiveType(mapping, type)); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value: " + jsonNode.asText() + " for property: " + name, e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); } }
final Geospatial.Dimension dimension = type == null || type.getName().startsWith("Geometry") ? Geospatial.Dimension.GEOMETRY : Geospatial.Dimension.GEOGRAPHY;
final Geospatial.Dimension dimension = type == null || type.getName().startsWith("Geometry") ? Geospatial.Dimension.GEOMETRY : Geospatial.Dimension.GEOGRAPHY;
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#Collection(" + type.getName() + ")"); writePrimitiveCollection(type, property, options == null ? null : options.isNullable(),
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#Collection(" + type.getName() + ")"); writePrimitiveCollection(type, property, options == null ? null : options.isNullable(),
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final EdmPrimitiveType edmPrimitiveType, final JsonNode jsonNode) throws DeserializerException { boolean valid = true; if (edmPrimitiveType.getKind() == EdmTypeKind.DEFINITION) { checkJsonTypeBasedOnPrimitiveType(propertyName, ((EdmTypeDefinition) edmPrimitiveType).getUnderlyingType(), jsonNode); } else if (edmPrimitiveType.getKind() == EdmTypeKind.ENUM) { // Enum values must be strings. valid = jsonNode.isTextual(); } else { final String name = edmPrimitiveType.getName(); EdmPrimitiveTypeKind primKind; try { primKind = EdmPrimitiveTypeKind.valueOf(name); } catch (final IllegalArgumentException e) { throw new DeserializerException("Unknown Primitive Type: " + name, e, DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, name, propertyName); } valid = matchTextualCase(jsonNode, primKind) || matchNumberCase(jsonNode, primKind) || matchBooleanCase(jsonNode, primKind) || matchIEEENumberCase(jsonNode, primKind) || jsonNode.isObject() && name.startsWith("Geo"); } if (!valid) { throw new DeserializerException( "Invalid json type: " + jsonNode.getNodeType() + " for " + edmPrimitiveType + " property: " + propertyName, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName); } }
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final EdmPrimitiveType edmPrimitiveType, final JsonNode jsonNode) throws DeserializerException { boolean valid = true; if (edmPrimitiveType.getKind() == EdmTypeKind.DEFINITION) { checkJsonTypeBasedOnPrimitiveType(propertyName, ((EdmTypeDefinition) edmPrimitiveType).getUnderlyingType(), jsonNode); } else if (edmPrimitiveType.getKind() == EdmTypeKind.ENUM) { // Enum values must be strings. valid = jsonNode.isTextual(); } else { final String name = edmPrimitiveType.getName(); EdmPrimitiveTypeKind primKind; try { primKind = EdmPrimitiveTypeKind.valueOf(name); } catch (final IllegalArgumentException e) { throw new DeserializerException("Unknown Primitive Type: " + name, e, DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, name, propertyName); } valid = matchTextualCase(jsonNode, primKind) || matchNumberCase(jsonNode, primKind) || matchBooleanCase(jsonNode, primKind) || matchIEEENumberCase(jsonNode, primKind) || jsonNode.isObject() && name.startsWith("Geo"); } if (!valid) { throw new DeserializerException( "Invalid json type: " + jsonNode.getNodeType() + " for " + edmPrimitiveType + " property: " + propertyName, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName); } }
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final EdmPrimitiveType edmPrimitiveType, final JsonNode jsonNode) throws DeserializerException { boolean valid = true; if (edmPrimitiveType.getKind() == EdmTypeKind.DEFINITION) { checkJsonTypeBasedOnPrimitiveType(propertyName, ((EdmTypeDefinition) edmPrimitiveType).getUnderlyingType(), jsonNode); } else if (edmPrimitiveType.getKind() == EdmTypeKind.ENUM) { // Enum values must be strings. valid = jsonNode.isTextual(); } else { final String name = edmPrimitiveType.getName(); EdmPrimitiveTypeKind primKind; try { primKind = EdmPrimitiveTypeKind.valueOf(name); } catch (final IllegalArgumentException e) { throw new DeserializerException("Unknown Primitive Type: " + name, e, DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, name, propertyName); } valid = matchTextualCase(jsonNode, primKind) || matchNumberCase(jsonNode, primKind) || matchBooleanCase(jsonNode, primKind) || matchIEEENumberCase(jsonNode, primKind); } if (!valid) { throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for " + edmPrimitiveType + " property: " + propertyName, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName); } }
private void writePrimitive(final EdmPrimitiveType type, final Property property, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final String xml10InvalidCharReplacement, final XMLStreamWriter writer) throws EdmPrimitiveTypeException, XMLStreamException, SerializerException { if (property.isPrimitive()) { if (type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, type.getKind() == EdmTypeKind.DEFINITION ? "#" + type.getFullQualifiedName().getFullQualifiedNameAsString() : type.getName()); } writePrimitiveValue(type, property.asPrimitive(), isNullable, maxLength, precision, scale, isUnicode, xml10InvalidCharReplacement, writer); } else if (property.isGeospatial()) { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); } else if (property.isEnum()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); writePrimitiveValue(type, property.asEnum(), isNullable, maxLength, precision, scale, isUnicode, xml10InvalidCharReplacement, writer); } else { throw new SerializerException("Inconsistent property type!", SerializerException.MessageKeys.INCONSISTENT_PROPERTY_TYPE, property.getName()); } }
private void writePrimitive(final EdmPrimitiveType type, final Property property, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final String xml10InvalidCharReplacement, final XMLStreamWriter writer) throws EdmPrimitiveTypeException, XMLStreamException, SerializerException { if (property.isPrimitive()) { if (type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, type.getKind() == EdmTypeKind.DEFINITION ? "#" + type.getFullQualifiedName().getFullQualifiedNameAsString() : type.getName()); } writePrimitiveValue(type, property.asPrimitive(), isNullable, maxLength, precision, scale, isUnicode, xml10InvalidCharReplacement, writer); } else if (property.isGeospatial()) { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); } else if (property.isEnum()) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); writePrimitiveValue(type, property.asEnum(), isNullable, maxLength, precision, scale, isUnicode, xml10InvalidCharReplacement, writer); } else { throw new SerializerException("Inconsistent property type!", SerializerException.MessageKeys.INCONSISTENT_PROPERTY_TYPE, property.getName()); } }