private EnumType( Class<?> type ) { super( type ); if( !isEnum( type ) ) { throw new IllegalArgumentException( type + " is not an Enum." ); } } }
public static EnumType of( Class<?> type ) { return new EnumType( type ); }
@Test public void givenEnumSetWhenSerializingAndDeserializingExpectEquals() { Set<SomeEnum> enumSet = EnumSet.allOf( SomeEnum.class ); String output = serialization.serialize( enumSet ); System.out.println( output ); CollectionType valueType = CollectionType.setOf( EnumType.of( SomeEnum.class ) ); Set<SomeEnum> value = serialization.deserialize( module, valueType, output ); assertEquals( enumSet, value ); }
@Test public void givenEnumValueWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = serialization.serialize( SomeEnum.BÆR ); System.out.println( output ); assertThat( getSingleStringRawState( output ), equalTo( "BÆR" ) ); SomeEnum value = serialization.deserialize( module, EnumType.of( SomeEnum.class ), output ); assertThat( value, is( SomeEnum.BÆR ) ); }
private EnumType( Class<?> type ) { super( type ); if( !isEnum( type ) ) { throw new IllegalArgumentException( type + " is not an Enum." ); } } }
@Test public void givenEnumSetWhenSerializingAndDeserializingExpectEquals() { Set<SomeEnum> enumSet = EnumSet.allOf( SomeEnum.class ); String output = serialization.serialize( enumSet ); System.out.println( output ); CollectionType valueType = CollectionType.setOf( EnumType.of( SomeEnum.class ) ); Set<SomeEnum> value = serialization.deserialize( module, valueType, output ); assertEquals( enumSet, value ); }
public static EnumType of( Class<?> type ) { return new EnumType( type ); }
Property<Object> property = state.propertyFor( accessor ); PropertyDescriptor propertyDescriptor = spi.propertyDescriptorFor( property ); if( EnumType.isEnum( propertyDescriptor.type() ) )
@Test public void givenEnumValueWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = serialization.serialize( SomeEnum.BÆR ); System.out.println( output ); assertThat( getSingleStringRawState( output ), equalTo( "BÆR" ) ); SomeEnum value = serialization.deserialize( module, EnumType.of( SomeEnum.class ), output ); assertThat( value, is( SomeEnum.BÆR ) ); }
Property<Object> property = state.propertyFor( accessor ); PropertyDescriptor propertyDescriptor = spi.propertyDescriptorFor( property ); if( EnumType.isEnum( propertyDescriptor.type() ) )
@Test public void givenEnumMapWhenSerializingAndDeserializingExpectEquals() { EnumMap<SomeEnum, Number> enumMap = new EnumMap<>( SomeEnum.class ); for( SomeEnum value : SomeEnum.values() ) { enumMap.put( value, 23 ); } String output = serialization.serialize( enumMap ); System.out.println( output ); MapType valueType = MapType.of( EnumType.of( SomeEnum.class ), ValueType.of( Integer.class ) ); Map<SomeEnum, Number> value = serialization.deserialize( module, valueType, output ); assertEquals( enumMap, value ); }
if( EnumType.isEnum( objectClass ) )
@Test public void givenEnumMapWhenSerializingAndDeserializingExpectEquals() { EnumMap<SomeEnum, Number> enumMap = new EnumMap<>( SomeEnum.class ); for( SomeEnum value : SomeEnum.values() ) { enumMap.put( value, 23 ); } String output = serialization.serialize( enumMap ); System.out.println( output ); MapType valueType = MapType.of( EnumType.of( SomeEnum.class ), ValueType.of( Integer.class ) ); Map<SomeEnum, Number> value = serialization.deserialize( module, valueType, output ); assertEquals( enumMap, value ); }
if( EnumType.isEnum( objectClass ) )
@Override public ValueType valueTypeOf( ModuleDescriptor module, Object object ) { if( object instanceof ValueComposite ) { ValueInstance valueInstance = (ValueInstance) compositeInstanceOf( (Composite) object ); return valueInstance.descriptor().valueType(); } if( object instanceof EntityComposite ) { return ( (EntityInstance) compositeInstanceOf( (Composite) object ) ).descriptor().valueType(); } if( object instanceof Enum ) { return EnumType.of( ( (Enum) object ).getDeclaringClass() ); } return valueTypeOf( module, object.getClass() ); }