public boolean isType(final ValueType type) { return getType() == type; }
@Override public NumberType getNumberType() throws IOException { final NumberType type; switch (currentValue.getType()) { case SMALLINT: type = NumberType.INT; break; case INT: type = NumberType.LONG; break; case UINT: type = NumberType.BIG_INTEGER; break; case DOUBLE: type = NumberType.DOUBLE; break; default: type = null; break; } return type; }
@Override public JsonToken nextToken() throws IOException { if (_currToken == null) { _currToken = getToken(currentValue.getType(), currentValue); return _currToken; _currToken = getToken(currentValue.getType(), currentValue); return _currToken; currentName = null; currentValue = lastArray.next(); _currToken = getToken(currentValue.getType(), currentValue); } else { _currToken = JsonToken.END_ARRAY;
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }
public Alias readAliasFrom(final VPackSlice source) { if (source.isArray()) { return Alias.NONE; } if (source.isObject()) { final VPackSlice typeKey = source.get(this.typeKey); return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null); } throw new IllegalArgumentException("Cannot read alias from VPack type " + source.getType()); }
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }
public Alias readAliasFrom(final VPackSlice source) { if (source.isArray()) { return Alias.NONE; } if (source.isObject()) { final VPackSlice typeKey = source.get(this.typeKey); return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null); } throw new IllegalArgumentException("Cannot read alias from VPack type " + source.getType()); }
private Object readMap(final TypeInformation<?> type, final VPackSlice source) { if (!source.isObject()) { throw new MappingException( String.format("Can't read map type %s from VPack type %s!", type, source.getType())); } final Class<?> keyType = getNonNullComponentType(type).getType(); final TypeInformation<?> valueType = getNonNullMapValueType(type); final Map<Object, Object> map = CollectionFactory.createMap(type.getType(), keyType, source.size()); final Iterator<Entry<String, VPackSlice>> iterator = source.objectIterator(); while (iterator.hasNext()) { final Entry<String, VPackSlice> entry = iterator.next(); if (typeMapper.isTypeKey(entry.getKey())) { continue; } final Object key = convertIfNecessary(entry.getKey(), keyType); final VPackSlice value = entry.getValue(); map.put(key, readInternal(valueType, value)); } return map; }
private Object readMap(final TypeInformation<?> type, final VPackSlice source) { if (!source.isObject()) { throw new MappingException( String.format("Can't read map type %s from VPack type %s!", type, source.getType())); } final Class<?> keyType = getNonNullComponentType(type).getType(); final TypeInformation<?> valueType = getNonNullMapValueType(type); final Map<Object, Object> map = CollectionFactory.createMap(type.getType(), keyType, source.size()); final Iterator<Entry<String, VPackSlice>> iterator = source.objectIterator(); while (iterator.hasNext()) { final Entry<String, VPackSlice> entry = iterator.next(); if (typeMapper.isTypeKey(entry.getKey())) { continue; } final Object key = convertIfNecessary(entry.getKey(), keyType); final VPackSlice value = entry.getValue(); map.put(key, readInternal(valueType, value)); } return map; }
@SuppressWarnings("unchecked") private Optional<Object> readReference( final VPackSlice source, final ArangoPersistentProperty property, final Annotation annotation) { final Optional<ReferenceResolver<Annotation>> resolver = resolverFactory.getReferenceResolver(annotation); if (!resolver.isPresent() || source.isNone()) { return Optional.empty(); } else if (property.isCollectionLike()) { final Collection<String> ids; try { ids = (Collection<String>) readCollection(ClassTypeInformation.COLLECTION, source); } catch (final ClassCastException e) { throw new MappingException("All references must be of type String!", e); } return resolver.map(res -> res.resolveMultiple(ids, property.getTypeInformation(), annotation)); } else { if (!source.isString()) { throw new MappingException( String.format("A reference must be of type String, but got VPack type %s!", source.getType())); } return resolver.map(res -> res.resolveOne(source.getAsString(), property.getTypeInformation(), annotation)); } }
@SuppressWarnings("unchecked") private Optional<Object> readReference( final VPackSlice source, final ArangoPersistentProperty property, final Annotation annotation) { final Optional<ReferenceResolver<Annotation>> resolver = resolverFactory.getReferenceResolver(annotation); if (!resolver.isPresent() || source.isNone()) { return Optional.empty(); } else if (property.isCollectionLike()) { final Collection<String> ids; try { ids = (Collection<String>) readCollection(ClassTypeInformation.COLLECTION, source); } catch (final ClassCastException e) { throw new MappingException("All references must be of type String!", e); } return resolver.map(res -> res.resolveMultiple(ids, property.getTypeInformation(), annotation)); } else { if (!source.isString()) { throw new MappingException( String.format("A reference must be of type String, but got VPack type %s!", source.getType())); } return resolver.map(res -> res.resolveOne(source.getAsString(), property.getTypeInformation(), annotation)); } }
throw new MappingException(String.format("Can't read type %s from VPack type %s!", type, source.getType()));
throw new MappingException(String.format("Can't read type %s from VPack type %s!", type, source.getType()));
if (attribute != null) { appendField(attribute, json); deserializer = getDeserializer(attribute, value.getType());
size = valueLength; } else { switch (getType()) { case ARRAY: case OBJECT:
private Object readEntity( final TypeInformation<?> type, final VPackSlice source, final ArangoPersistentEntity<?> entity) { if (!source.isObject()) { throw new MappingException( String.format("Can't read entity type %s from VPack type %s!", type, source.getType())); } final EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final ParameterValueProvider<ArangoPersistentProperty> provider = getParameterProvider(entity, source); final Object instance = instantiator.createInstance(entity, provider); final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(instance); final String id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; entity.doWithProperties((final ArangoPersistentProperty property) -> { if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); entity.doWithAssociations((final Association<ArangoPersistentProperty> association) -> { final ArangoPersistentProperty property = association.getInverse(); if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); return instance; }
private Object readEntity( final TypeInformation<?> type, final VPackSlice source, final ArangoPersistentEntity<?> entity) { if (!source.isObject()) { throw new MappingException( String.format("Can't read entity type %s from VPack type %s!", type, source.getType())); } final EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final ParameterValueProvider<ArangoPersistentProperty> provider = getParameterProvider(entity, source); final Object instance = instantiator.createInstance(entity, provider); final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(instance); final String id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; entity.doWithProperties((final ArangoPersistentProperty property) -> { if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); entity.doWithAssociations((final Association<ArangoPersistentProperty> association) -> { final ArangoPersistentProperty property = association.getInverse(); if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); return instance; }