Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveType#getKind()
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmPrimitiveType#getKind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * Returns the primitive type's default class or the manually mapped class if present. * @param mapping * @param edmPrimitiveType * @return the java class to be used during deserialization */ private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType type) { final EdmPrimitiveType edmPrimitiveType = type.getKind() == EdmTypeKind.ENUM ? ((EdmEnumType) type).getUnderlyingType() : type .getKind() == EdmTypeKind.DEFINITION ? ((EdmTypeDefinition) type).getUnderlyingType() : type; return mapping == null || mapping.getMappedJavaClass() == null ? edmPrimitiveType.getDefaultType() : mapping .getMappedJavaClass(); }
Example 2
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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); } }
Example 3
Source File: ParserHelper.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private static boolean nextPrimitiveTypeValue(UriTokenizer tokenizer, final EdmPrimitiveType primitiveType, final boolean nullable) { final EdmPrimitiveType type = primitiveType instanceof EdmTypeDefinition ? ((EdmTypeDefinition) primitiveType).getUnderlyingType() : primitiveType; if (tokenizer.next(TokenKind.ParameterAliasName)) { return true; } else if (nullable && tokenizer.next(TokenKind.NULL)) { return true; // Special handling for frequently-used types and types with more than one token kind. } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean).equals(type)) { return tokenizer.next(TokenKind.BooleanValue); } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String).equals(type)) { return tokenizer.next(TokenKind.StringValue); } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte).equals(type) || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte).equals(type) || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16).equals(type) || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32).equals(type) || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64).equals(type)) { return tokenizer.next(TokenKind.IntegerValue); } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid).equals(type)) { return tokenizer.next(TokenKind.GuidValue); } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal).equals(type)) { // The order is important. // A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point. return tokenizer.next(TokenKind.DecimalValue) || tokenizer.next(TokenKind.IntegerValue); } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double).equals(type) || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single).equals(type)) { // The order is important. // A floating-point value should not be parsed as decimal and let the tokenizer stop at 'E'. // A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point. return tokenizer.next(TokenKind.DoubleValue) || tokenizer.next(TokenKind.DecimalValue) || tokenizer.next(TokenKind.IntegerValue); } else if (type.getKind() == EdmTypeKind.ENUM) { return tokenizer.next(TokenKind.EnumValue); } else { // Check the types that have not been checked already above. for (final Entry<TokenKind, EdmPrimitiveTypeKind> entry : tokenToPrimitiveType.entrySet()) { final EdmPrimitiveTypeKind kind = entry.getValue(); if ((kind == EdmPrimitiveTypeKind.Date || kind == EdmPrimitiveTypeKind.DateTimeOffset || kind == EdmPrimitiveTypeKind.TimeOfDay || kind == EdmPrimitiveTypeKind.Duration || kind == EdmPrimitiveTypeKind.Binary || kind.isGeospatial()) && odata.createPrimitiveTypeInstance(kind).equals(type)) { return tokenizer.next(entry.getKey()); } } return false; } }