Search in sources :

Example 1 with ValueType

use of org.qi4j.api.type.ValueType 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;
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) ValueType(org.qi4j.api.type.ValueType) HashMap(java.util.HashMap) QualifiedName(org.qi4j.api.common.QualifiedName) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Example 2 with ValueType

use of org.qi4j.api.type.ValueType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenCollectionTypeWithBigDecimalAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenCollectionTypeWithBigDecimalAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(bigDecimalCollection());
    CollectionType collectionType = new CollectionType(Collection.class, new ValueType(BigDecimal.class));
    Collection<BigDecimal> collection = valueSerialization.deserialize(collectionType, output);
    assertEquals(bigDecimalCollection(), collection);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) BigDecimal(java.math.BigDecimal) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 3 with ValueType

use of org.qi4j.api.type.ValueType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenCollectionTypeWithFloatAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenCollectionTypeWithFloatAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(floatCollection());
    CollectionType collectionType = new CollectionType(List.class, new ValueType(Float.class));
    List<Float> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(floatCollection(), list);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 4 with ValueType

use of org.qi4j.api.type.ValueType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenListOfMapStringStringAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenListOfMapStringStringAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(stringListOfMaps());
    ValueType stringType = new ValueType(String.class);
    CollectionType collectionType = new CollectionType(List.class, new MapType(Map.class, stringType, stringType));
    List<Map<String, String>> value = valueSerialization.deserialize(collectionType, output);
    assertEquals(stringListOfMaps(), value);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MapType(org.qi4j.api.type.MapType) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 5 with ValueType

use of org.qi4j.api.type.ValueType 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);
}
Also used : ValueType(org.qi4j.api.type.ValueType) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) ValueSerializationException(org.qi4j.api.value.ValueSerializationException) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Aggregations

ValueType (org.qi4j.api.type.ValueType)23 CollectionType (org.qi4j.api.type.CollectionType)16 Test (org.junit.Test)13 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)13 ValueCompositeType (org.qi4j.api.type.ValueCompositeType)8 MapType (org.qi4j.api.type.MapType)6 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)5 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 QualifiedName (org.qi4j.api.common.QualifiedName)3 EntityReference (org.qi4j.api.entity.EntityReference)3 EnumType (org.qi4j.api.type.EnumType)3 BigInteger (java.math.BigInteger)2 Preferences (java.util.prefs.Preferences)2 URI (org.openrdf.model.URI)2 ValueFactory (org.openrdf.model.ValueFactory)2 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)2