@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (rawType.getName().equals(Dummy.class.getName())) {
return new ParamConverter<T>() {
@Override
public T fromString(String value) {
Dummy dummy = new Dummy(value);
return rawType.cast(dummy);
}
@Override
public String toString(T myDummy) {
if (myDummy == null) {
return null;
}
return myDummy.toString();
}
};
}
return null;
}
java类javax.ws.rs.ext.ParamConverter的实例源码
DummyParamProvider.java 文件源码
项目:rest.vertx
阅读 19
收藏 0
点赞 0
评论 0
ResourceModule.java 文件源码
项目:mentor
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void configure() {
// providers
bind(ObjectMapperProvider.class);
bind(GuiceParamConverterProvider.class);
bind(ExceptionMapperProvider.class);
// params
bind(ParamConverter.class).annotatedWith(JaxRsParams.forClass(User.class)).to(UserParamConverter.class);
bind(ParamConverter.class).annotatedWith(JaxRsParams.forClass(Course.class)).to(CourseParamConverter.class);
bind(ParamConverter.class).annotatedWith(JaxRsParams.forClass(Lecture.class)).to(LectureParamConverter.class);
bind(ParamConverter.class).annotatedWith(JaxRsParams.forClass(Unit.class)).to(UnitParamConverter.class);
// resources
bind(RootResource.class);
bind(UserResource.class);
bind(CourseResource.class);
bind(LectureResource.class);
bind(UnitResource.class);
}
DateParamModelConvertorProvider.java 文件源码
项目:jersey-jax-rs-examples
阅读 23
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (rawType.getName().equals(DateParamModel.class.getName())) {
return new ParamConverter<T>() {
@SuppressWarnings("unchecked")
@Override
public T fromString(String value) {
DateParamModel dateParamModel = new DateParamModel();
dateParamModel.setDateAsString(value);
return (T) dateParamModel;
}
@Override
public String toString(T bean) {
return ((DateParamModel) bean).getDateAsString();
}
};
}
return null;
}
CommonTypesParamConverterProvider.java 文件源码
项目:stdlib
阅读 17
收藏 0
点赞 0
评论 0
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations)
{
if (rawType == null)
return null;
else if (rawType.equals(DateTime.class))
return dateTime;
else if (rawType.equals(LocalDateTime.class))
return localDateTime;
else if (rawType.equals(LocalDate.class))
return localDate;
else if (rawType.equals(Period.class))
return period;
else if (rawType.equals(Duration.class))
return duration;
else if (rawType.equals(LocalTime.class))
return localTime;
else
return null;
}
MoshiParamConverterFactory.java 文件源码
项目:jax-rs-moshi
阅读 18
收藏 0
点赞 0
评论 0
@Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType,
Annotation[] annotations) {
for (Annotation annotation : annotations) {
if (annotation instanceof Json) {
JsonAdapter<T> adapter = moshi.adapter(genericType);
return new MoshiParamConverter<>(adapter);
}
}
return null;
}
MoshiParamConverterFactoryTest.java 文件源码
项目:jax-rs-moshi
阅读 25
收藏 0
点赞 0
评论 0
@Test public void differentJsonAnnotationReturnsNull() {
ParamConverter<String> converter =
provider.getConverter(String.class, String.class, new Annotation[] {
Annotations.other()
});
assertNull(converter);
}
MoshiParamConverterFactoryTest.java 文件源码
项目:jax-rs-moshi
阅读 23
收藏 0
点赞 0
评论 0
@Test public void jsonAnnotationReturnsConverterClass() {
ParamConverter<String> converter =
provider.getConverter(String.class, String.class, new Annotation[] {
Annotations.real()
});
String value = converter.fromString("\"hey\"");
assertEquals("hey", value);
String json = converter.toString("hey");
assertEquals("\"hey\"", json);
}
MoshiParamConverterFactoryTest.java 文件源码
项目:jax-rs-moshi
阅读 22
收藏 0
点赞 0
评论 0
@Test public void jsonAnnotationReturnsConverterParameterized() {
Type genericType = Types.newParameterizedType(List.class, String.class);
ParamConverter<List<String>> converter =
(ParamConverter) provider.getConverter(List.class, genericType, new Annotation[] {
Annotations.real()
});
List<String> value = converter.fromString("[\"hey\"]");
assertEquals(singletonList("hey"), value);
String json = converter.toString(singletonList("hey"));
assertEquals("[\"hey\"]", json);
}
DateParameterConverterProvider.java 文件源码
项目:grooves
阅读 18
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> type, Type type1, Annotation[] antns) {
if (Date.class.equals(type)) {
@SuppressWarnings("unchecked")
ParamConverter<T> paramConverter = (ParamConverter<T>) new DateParameterConverter();
return paramConverter;
}
return null;
}
MinijaxProviders.java 文件源码
项目:minijax
阅读 25
收藏 0
点赞 0
评论 0
public <T> ParamConverter<T> getParamConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
for (final ParamConverterProvider provider : paramConverterProviders) {
final ParamConverter<T> converter = provider.getConverter(rawType, genericType, annotations);
if (converter != null) {
return converter;
}
}
return null;
}
JsonParamConverterProvider.java 文件源码
项目:factcast
阅读 19
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType,
Annotation[] annotations) {
if (annotations != null && Arrays.stream(annotations)
.filter(a -> a instanceof JsonParam)
.findAny()
.isPresent() && !Collection.class.isAssignableFrom(rawType)) {
return new JsonParamConverter<T>(objectMapper, rawType);
}
return null;
}
LocalDateTimeConverterProvider.java 文件源码
项目:PiCameraProject
阅读 19
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] antns) {
System.out.println("Checking conversion of " + clazz.getName());
if(LocalDateTime.class.equals(clazz)){
return (ParamConverter<T>) new LocalDateTimeConverter();
}
return null;
}
TestParamConverterProvider.java 文件源码
项目:microprofile-rest-client
阅读 23
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> aClass, Type type, Annotation[] annotations) {
if(String.class.isAssignableFrom(aClass)) {
return (ParamConverter<T>) new TestParamConverter();
}
return null;
}
UnixTimestampParameterHandler.java 文件源码
项目:bootstrap
阅读 22
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) { // NOSONAR
// Basic date handler
if (rawType.equals(Date.class)) {
return (ParamConverter<T>) converter;
}
// LocalDate handler
if (rawType.equals(LocalDate.class)) {
return (ParamConverter<T>) localDateconverter;
}
return null;
}
CustomConverterProvider.java 文件源码
项目:eplmp
阅读 21
收藏 0
点赞 0
评论 0
@Override
// Safe cast, ignore warning
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
if (clazz.getName().equals(Date.class.getName())) {
return (ParamConverter<T>) dateAdapter;
}
return null;
}
GuiceParamConverterProvider.java 文件源码
项目:mentor
阅读 20
收藏 0
点赞 0
评论 0
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
Binding<ParamConverter> binding = injector.getExistingBinding(Key.get(ParamConverter.class, JaxRsParams.forClass(rawType)));
if (binding == null)
return null;
return binding.getProvider().get();
}
JavaTimeParamConverterProviderTest.java 文件源码
项目:starwizard
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void getLocalDateConverter() throws Exception {
JavaTimeParamConverterProvider provider = new JavaTimeParamConverterProvider();
ParamConverter<LocalDate> converter = provider.getConverter(LocalDate.class, null, null);
assertNull(converter.fromString(null));
assertEquals(LocalDate.of(2017, 5, 12), converter.fromString("2017-05-12"));
assertEquals("2017-05-12", converter.toString(LocalDate.of(2017, 5, 12)));
}
JavaTimeParamConverterProviderTest.java 文件源码
项目:starwizard
阅读 18
收藏 0
点赞 0
评论 0
@Test
public void getInstantConverter() throws Exception {
JavaTimeParamConverterProvider provider = new JavaTimeParamConverterProvider();
ParamConverter<Instant> converter = provider.getConverter(Instant.class, null, null);
assertNull(converter.fromString(null));
Instant instant = Instant.parse("2017-04-05T14:44:16.677Z"); // epoch milli 1491403456677
assertEquals(instant, converter.fromString("2017-04-05T14:44:16.677Z"));
assertEquals(instant, converter.fromString("1491403456677"));
assertEquals("2017-04-05T14:44:16.677Z", converter.toString(instant));
}
TimeParamProvider.java 文件源码
项目:Plume
阅读 21
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (rawType == LocalDate.class) {
return (ParamConverter<T>) LOCAL_DATE_CONVERTER;
}
if (rawType == LocalDateTime.class) {
return (ParamConverter<T>) LOCAL_DATE_TIME_CONVERTER;
}
if (rawType == Instant.class) {
return (ParamConverter<T>) INSTANT_CONVERTER;
}
return null;
}
OptionalParamProvider.java 文件源码
项目:swiftproxy
阅读 20
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(Class<T> aClass, Type type, Annotation[] annotations) {
if (aClass == Optional.class) {
try {
return (ParamConverter<T>) new OptionalParamConverter(type);
} catch (NoSuchMethodException | IllegalArgumentException e) {
return null;
}
}
return null;
}
ConvertersProvider.java 文件源码
项目:hawkular-client-java
阅读 21
收藏 0
点赞 0
评论 0
public ConvertersProvider() {
ImmutableMap.Builder<Class<?>, ParamConverter<?>> paramConvertersBuilder = ImmutableMap.builder();
paramConverters = paramConvertersBuilder
.put(Duration.class, new DurationConverter())
.put(Tags.class, new TagsConverter())
.put(Order.class, new OrderConverter())
.put(Percentiles.class, new PercentilesConverter())
.build();
}
OmParamConverterProvider.java 文件源码
项目:openmeetings
阅读 20
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (Calendar.class.isAssignableFrom(rawType)) {
return (ParamConverter<T>)new CalendarParamConverter();
} else if (Date.class.isAssignableFrom(rawType)) {
return (ParamConverter<T>)new DateParamConverter();
} else if (AppointmentDTO.class.isAssignableFrom(rawType)) {
return (ParamConverter<T>)new AppointmentParamConverter();
} else if (UserDTO.class.isAssignableFrom(rawType)) {
return (ParamConverter<T>)new UserParamConverter();
}
return null;
}
TinyTypesParamProvider.java 文件源码
项目:tinytypes
阅读 21
收藏 0
点赞 0
评论 0
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) {
if (MetaTinyTypes.isTinyType(rawType)) {
return new TinyTypesParamConverter<>(rawType);
}
return null;
}
DateParamConverterProvider.java 文件源码
项目:syncope
阅读 20
收藏 0
点赞 0
评论 0
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(
final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
if (Date.class.equals(rawType)) {
return (ParamConverter<T>) new DateParamConverter();
}
return null;
}
ConvertersProvider.java 文件源码
项目:hawkular-metrics
阅读 21
收藏 0
点赞 0
评论 0
public ConvertersProvider() {
ImmutableMap.Builder<Class<?>, ParamConverter<?>> paramConvertersBuilder = ImmutableMap.builder();
paramConverters = paramConvertersBuilder
.put(Duration.class, new DurationConverter())
.put(Tags.class, new TagsConverter())
.put(TagNames.class, new TagNamesConverter())
.put(MetricType.class, new MetricTypeConverter())
.put(Order.class, new OrderConverter())
.put(Percentiles.class, new PercentilesConverter())
.build();
}
MyMessageParamConverterProvider.java 文件源码
项目:dropwizard-java8
阅读 22
收藏 0
点赞 0
评论 0
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (genericType.equals(MyMessage.class)) {
return (ParamConverter<T>) new MyMessageParamConverter();
}
return null;
}
AgentStringReaderProvider.java 文件源码
项目:Larissa
阅读 19
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> arg0, Type arg1,
Annotation[] arg2) {
if (arg1.equals(Agent.class)) {
return (ParamConverter<T>) new AgentParamConverter();
}
return null;
}
DateParamConverterProvider.java 文件源码
项目:Larissa
阅读 27
收藏 0
点赞 0
评论 0
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ParamConverter getConverter(Class arg0, Type arg1, Annotation[] arg2) {
if (arg1.equals(Date.class)) {
return new DateParamConverter();
} else {
return null;
}
}
RESTService.java 文件源码
项目:tomee
阅读 22
收藏 0
点赞 0
评论 0
private static <T> boolean isProvider(final Class<T> clazz) {
return MessageBodyReader.class.isAssignableFrom(clazz) ||
MessageBodyWriter.class.isAssignableFrom(clazz) ||
ParamConverter.class.isAssignableFrom(clazz) ||
ContainerRequestFilter.class.isAssignableFrom(clazz) ||
ContainerResponseFilter.class.isAssignableFrom(clazz) ||
ReaderInterceptor.class.isAssignableFrom(clazz) ||
WriterInterceptor.class.isAssignableFrom(clazz) ||
ParamConverterProvider.class.isAssignableFrom(clazz) ||
ContextResolver.class.isAssignableFrom(clazz) ||
new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
}
MoshiParamConverterFactoryTest.java 文件源码
项目:jax-rs-moshi
阅读 20
收藏 0
点赞 0
评论 0
@Test public void noAnnotationReturnsNull() {
ParamConverter<String> converter =
provider.getConverter(String.class, String.class, new Annotation[0]);
assertNull(converter);
}