Search in sources :

Example 21 with ValueType

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

the class AbstractCollectionSerializationTest method givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(Iterables.iterable(byteCollection().toArray()));
    CollectionType collectionType = new CollectionType(List.class, new ValueType(Byte.class));
    List<Byte> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(byteCollection(), 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 22 with ValueType

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

the class AbstractCollectionSerializationTest method givenCollectionTypeWithShortAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenCollectionTypeWithShortAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(shortCollection());
    CollectionType collectionType = new CollectionType(List.class, new ValueType(Short.class));
    List<Short> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(shortCollection(), 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 23 with ValueType

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

the class GaeEntityState method propertyValueOf.

@Override
public Object propertyValueOf(QualifiedName stateName) {
    String uri = stateName.toURI();
    Object value = entity.getProperty(uri);
    if (value instanceof Text) {
        value = ((Text) value).getValue();
    }
    ValueType type = valueTypes.get(stateName);
    if (value != null && type != null) {
        try {
            value = valueSerialization.deserialize(type, value.toString());
        } catch (ValueSerializationException e) {
            String message = "\nqualifiedName: " + stateName + "\n    stateName: " + stateName.name() + "\n          uri: " + uri + "\n         type: " + type + "\n        value: " + value + "\n";
            InternalError error = new InternalError(message);
            error.initCause(e);
            throw error;
        }
    }
    System.out.println("getProperty( " + stateName + " )  -->  " + uri + "=" + value);
    return value;
}
Also used : ValueType(org.qi4j.api.type.ValueType) ValueSerializationException(org.qi4j.api.value.ValueSerializationException) Text(com.google.appengine.api.datastore.Text)

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