public static CollectionType setOf( Class<?> collectedType ) { return new CollectionType( Set.class, ValueType.of( collectedType ) ); } private ValueType collectedType;
@Override public String toString() { return super.toString() + "<" + keyType + "," + valueType + ">"; } }
@Test public void givenMapOfStringListStringAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( stringMultiMap() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( String.class ) ); MapType mapType = new MapType( Map.class, new ValueType( String.class ), collectionType ); Map<String, List<String>> value = valueSerialization.deserialize( mapType, output ); assertEquals( stringMultiMap(), value ); }
public static boolean isPrimitiveValueType( ValueType valueType ) { return isPrimitiveValueType( valueType.mainType() ); }
@Override public boolean satisfiedBy( ValueType valueType ) { return valueType instanceof CollectionType && ( (CollectionType) valueType ).collectedType().mainType().equals( String.class ); } };
@Override public boolean satisfiedBy( ValueType valueType ) { return valueType.mainType().equals( String.class ); } };
@Test public void givenCollectionTypeWithCharacterAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( characterCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Character.class ) ); List<Character> list = valueSerialization.deserialize( collectionType, output ); assertEquals( characterCollection(), list ); }
public static ValueType of( Class<?> type ) { return new ValueType( type ); }
public static EnumType of( Class<?> type ) { return new EnumType( type ); }
public CollectionType( Class<?> type, ValueType collectedType ) { super( type ); this.collectedType = collectedType; if( !isCollection( type ) ) { throw new IllegalArgumentException( type + " is not a Collection, List or Set." ); } }
public EnumType( Class<?> type ) { super( type ); if( !isEnum( type ) ) { throw new IllegalArgumentException( type + " is not an Enum." ); } } }
public MapType( Class<?> type, ValueType keyType, ValueType valueType, Serialization.Variant variant ) { super( type ); this.keyType = keyType; this.valueType = valueType; this.variant = variant; if( !isMap( type ) ) { throw new IllegalArgumentException( type + " is not a Map." ); } }
@Override public boolean satisfiedBy( HasTypes item ) { for( Class<?> type : item.types() ) { if( matchType.isAssignableFrom( type ) ) { return true; } } return false; } }
@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 ); }
public static CollectionType collectionOf( Class<?> collectedType ) { return new CollectionType( Collection.class, ValueType.of( collectedType ) ); }
@Override public String toString() { return super.toString() + "<" + collectedType + ">"; } }
public static CollectionType listOf( Class<?> collectedType ) { return new CollectionType( List.class, ValueType.of( collectedType ) ); }