public static ArrayType of( Class<?> arrayType ) { return new ArrayType( arrayType, ValueType.of( arrayType.getComponentType() ) ); }
/** * Find a matching converter amongst registered ones. * * See {@link org.apache.polygene.api.type.HasTypesCollectors#closestType(HasTypes)}. * * @param type the value type * @param <T> the converted type * @return the closest matching registered converter, or {@literal null} if none */ default <T> Converter<T> converterFor( Class<? extends T> type ) { return converterFor( ValueType.of( type ) ); }
public static CollectionType of( Class<?> type, Class<?> collectedType ) { return of( type, ValueType.of( collectedType ) ); }
default <T> JavaxXmlAdapter<T> adapterFor( Class<T> type ) { return adapterFor( ValueType.of( type ) ); }
default <T> MessagePackAdapter<T> adapterFor( Class<T> type ) { return adapterFor( ValueType.of( type ) ); }
default <T> JavaxJsonAdapter<T> adapterFor( Class<T> type ) { return adapterFor( ValueType.of( type ) ); }
public static CollectionType of( Class<?> type, Class<?> collectedType ) { return of( type, ValueType.of( collectedType ) ); }
/** * Find a matching converter amongst registered ones. * * See {@link org.apache.polygene.api.type.HasTypesCollectors#closestType(HasTypes)}. * * @param type the value type * @param <T> the converted type * @return the closest matching registered converter, or {@literal null} if none */ default <T> Converter<T> converterFor( Class<? extends T> type ) { return converterFor( ValueType.of( type ) ); }
public JavaxJsonSettings withJsonAdapter( JavaxJsonAdapter<?> adapter ) { return withJsonAdapter( ValueType.of( adapter.type() ), adapter ); } }
public final SettingsType withConverter( Converter<Object> adapter ) { return withConverter( ValueType.of( adapter.type() ), adapter ); } }
public final SettingsType withConverter( Converter<Object> adapter ) { return withConverter( ValueType.of( adapter.type() ), adapter ); } }
@Test public void givenNullValueWhenSerializingAndDeserializingExpectNull() { String output = serialization.serialize( null ); System.out.println( output ); assertThat( serialization.deserialize( module, ValueType.of( Integer.class ), output ), nullValue() ); assertThat( serialization.deserialize( module, ValueType.of( String.class ), output ), nullValue() ); assertThat( serialization.deserialize( module, ValueType.of( SomeEnum.class ), output ), nullValue() ); }
public JavaxJsonSettings withJsonAdapter( JavaxJsonAdapter<?> adapter ) { return withJsonAdapter( ValueType.of( adapter.type() ), adapter ); } }
@Test public void givenNullValueWhenSerializingAndDeserializingExpectNull() { String output = serialization.serialize( null ); System.out.println( output ); assertThat( serialization.deserialize( module, ValueType.of( Integer.class ), output ), nullValue() ); assertThat( serialization.deserialize( module, ValueType.of( String.class ), output ), nullValue() ); assertThat( serialization.deserialize( module, ValueType.of( SomeEnum.class ), output ), nullValue() ); }
@Test public void hasAssignableTypePredicate() { assertTrue( new HasAssignableFromType<>( Number.class ) .test( ValueType.of( String.class, Integer.class ) ) ); assertFalse( new HasAssignableFromType<>( Integer.class ) .test( ValueType.of( Integer.class ) ) ); assertFalse( new HasAssignableFromType<>( String.class ) .test( ValueType.of( LocalDate.class, Integer.class ) ) ); }
@Test public void hasEqualOrAssignablePredicate() { assertTrue( new HasEqualOrAssignableFromType<>( Number.class ) .test( ValueType.of( String.class, Integer.class ) ) ); assertTrue( new HasEqualOrAssignableFromType<>( Integer.class ) .test( ValueType.of( Integer.class ) ) ); assertFalse( new HasEqualOrAssignableFromType<>( String.class ) .test( ValueType.of( LocalDate.class, Integer.class ) ) ); } }
@Override public CustomStructure deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { if( json.getValueType() != JsonValue.ValueType.OBJECT ) { throw new SerializationException( "Don't know how to deserialize CustomStructure from " + json ); } JsonObject jsonObject = (JsonObject) json; String foo = jsonObject.getString( "foo" ); LocalDate bar = (LocalDate) deserialize.apply( jsonObject.get( "bar" ), ValueType.of( LocalDate.class ) ); return new CustomStructure( foo, bar ); } }