use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class ValueDeserializerAdapter method deserializeNodeValueComposite.
private <T> T deserializeNodeValueComposite(ValueType valueType, InputNodeType inputNode) throws Exception {
ValueCompositeType valueCompositeType = (ValueCompositeType) valueType;
Class<?> valueBuilderType = first(valueCompositeType.types());
String typeInfo = this.<String>getObjectFieldValue(inputNode, "_type", this.<String>buildDeserializeInputNodeFunction(new ValueType(String.class)));
TREE_PARSING_LOG.trace("In deserializeNodeValueComposite(), getObjectFieldValue( {} ) returned '{}'", inputNode, typeInfo);
if (typeInfo != null) {
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(typeInfo);
if (valueDescriptor == null) {
throw new ValueSerializationException("Specified value type could not be resolved: " + typeInfo);
}
valueCompositeType = valueDescriptor.valueType();
valueBuilderType = Class.forName(typeInfo);
if (!valueType.equals(valueCompositeType)) {
TREE_PARSING_LOG.debug("Overriding {} with {} as defined in _type field.", valueType, valueCompositeType);
}
}
return deserializeValueComposite(valueCompositeType, valueBuilderType, inputNode);
}
use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class ValueDeserializerAdapter method deserializeNodeGuessed.
@SuppressWarnings("unchecked")
private <T> T deserializeNodeGuessed(ValueType valueType, InputNodeType inputNode) throws Exception {
if (isObjectValue(inputNode)) {
// Attempt ValueComposite deserialization
ValueCompositeType valueCompositeType;
if (// with _type info
objectHasField(inputNode, "_type")) {
String typeInfo = this.<String>getObjectFieldValue(inputNode, "_type", this.<String>buildDeserializeInputNodeFunction(new ValueType(String.class)));
TREE_PARSING_LOG.trace("In deserializeNodeGuessed(), getObjectFieldValue( {} ) returned '{}'", inputNode, typeInfo);
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(typeInfo);
if (valueDescriptor == null) {
throw new ValueSerializationException("Specified value type could not be resolved: " + typeInfo);
}
valueCompositeType = valueDescriptor.valueType();
TREE_PARSING_LOG.debug("Overriding {} with {} as defined in _type field.", valueType, valueCompositeType);
} else // without _type info
{
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(first(valueType.types()).getName());
if (valueDescriptor == null) {
throw new ValueSerializationException("Don't know how to deserialize " + inputNode);
}
valueCompositeType = valueDescriptor.valueType();
TREE_PARSING_LOG.debug("Overriding {} with {} as found in available ValueComposites.", valueType, valueCompositeType);
}
Class<?> valueBuilderType = first(valueCompositeType.types());
return deserializeValueComposite(valueCompositeType, valueBuilderType, inputNode);
}
// Last resort : base64 java deserialization
return (T) deserializeBase64Serialized(inputNode);
}
use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class GaeEntityState method initializeValueTypes.
private HashMap<QualifiedName, ValueType> initializeValueTypes(EntityDescriptor descriptor) {
HashMap<QualifiedName, ValueType> result = new HashMap<QualifiedName, ValueType>();
for (PropertyDescriptor persistent : descriptor.state().properties()) {
if (persistent.valueType() instanceof ValueCompositeType) {
QualifiedName name = persistent.qualifiedName();
result.put(name, persistent.valueType());
}
}
return result;
}
use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class AbstractCollectionSerializationTest method givenListOfValueCompositesAndNullElementWhenSerializingAndDeserializingExpectEquals.
@Test
public void givenListOfValueCompositesAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
String output = valueSerialization.serialize(valueCompositesList());
ValueCompositeType valueType = module.valueDescriptor(SomeValue.class.getName()).valueType();
CollectionType collectionType = new CollectionType(List.class, valueType);
List<SomeValue> value = valueSerialization.deserialize(collectionType, output);
assertEquals(valueCompositesList(), value);
}
use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class EntityStateSerializer method serializeValueComposite.
private void serializeValueComposite(Resource subject, URI predicate, ValueComposite value, ValueType valueType, Graph graph, String baseUri, boolean includeNonQueryable) {
final ValueFactory valueFactory = graph.getValueFactory();
BNode collection = valueFactory.createBNode();
graph.add(subject, predicate, collection);
for (PropertyDescriptor persistentProperty : ((ValueCompositeType) valueType).properties()) {
Object propertyValue = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map((Composite) value).state().propertyFor(persistentProperty.accessor()).get();
if (propertyValue == null) {
// Skip null values
continue;
}
ValueType type = persistentProperty.valueType();
if (type instanceof ValueCompositeType) {
URI pred = valueFactory.createURI(baseUri, persistentProperty.qualifiedName().name());
serializeValueComposite(collection, pred, (ValueComposite) propertyValue, type, graph, baseUri + persistentProperty.qualifiedName().name() + "/", includeNonQueryable);
} else {
serializeProperty(persistentProperty, propertyValue, collection, graph, includeNonQueryable);
}
}
}
Aggregations