use of javax.ws.rs.ext.ParamConverter in project cxf by apache.
the class JavaTimeTypesParamConverterProviderTest method offsetTime.
@Test
public void offsetTime() {
OffsetTime offsetTime = OffsetTime.of(10, 33, 24, 5, ZoneOffset.ofHours(2));
ParamConverter<OffsetTime> converter = (ParamConverter<OffsetTime>) provider.getConverter(offsetTime.getClass(), offsetTime.getClass(), offsetTime.getClass().getAnnotations());
Assert.assertEquals(offsetTime, converter.fromString(converter.toString(offsetTime)));
}
use of javax.ws.rs.ext.ParamConverter in project cxf by apache.
the class JavaTimeTypesParamConverterProviderTest method offsetDateTime.
@Test
public void offsetDateTime() {
OffsetDateTime offsetDateTime = OffsetDateTime.of(2016, 2, 24, 5, 55, 0, 0, ZoneOffset.UTC);
ParamConverter<OffsetDateTime> converter = (ParamConverter<OffsetDateTime>) provider.getConverter(offsetDateTime.getClass(), offsetDateTime.getClass(), offsetDateTime.getClass().getAnnotations());
Assert.assertEquals(offsetDateTime, converter.fromString(converter.toString(offsetDateTime)));
}
use of javax.ws.rs.ext.ParamConverter in project dropwizard by dropwizard.
the class OptionalParamConverterProvider method getConverter.
/**
* {@inheritDoc}
*/
@Override
@Nullable
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
if (Optional.class.equals(rawType)) {
final List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(genericType);
final ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null;
if (ctp == null || ctp.rawClass() == String.class) {
return new ParamConverter<T>() {
@Override
public T fromString(final String value) {
return rawType.cast(Optional.fromNullable(value));
}
@Override
public String toString(final T value) {
return value.toString();
}
};
}
for (ParamConverterProvider provider : Providers.getProviders(manager, ParamConverterProvider.class)) {
final ParamConverter<?> converter = provider.getConverter(ctp.rawClass(), ctp.type(), annotations);
if (converter != null) {
return new ParamConverter<T>() {
@Override
public T fromString(final String value) {
final Object convertedValue = value == null ? null : converter.fromString(value);
return rawType.cast(Optional.fromNullable(convertedValue));
}
@Override
public String toString(final T value) {
return value.toString();
}
};
}
}
}
return null;
}
Aggregations