Java 类javax.ws.rs.ext.ParamConverter 实例源码

项目:rest.vertx    文件:DummyParamProvider.java   
@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;
}
项目:mentor    文件:ResourceModule.java   
@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);

}
项目:jersey-jax-rs-examples    文件:DateParamModelConvertorProvider.java   
@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;
}
项目:stdlib    文件:CommonTypesParamConverterProvider.java   
@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;
}
项目:jax-rs-moshi    文件:MoshiParamConverterFactory.java   
@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;
}
项目:jax-rs-moshi    文件:MoshiParamConverterFactoryTest.java   
@Test public void differentJsonAnnotationReturnsNull() {
  ParamConverter<String> converter =
      provider.getConverter(String.class, String.class, new Annotation[] {
          Annotations.other()
      });
  assertNull(converter);
}
项目:jax-rs-moshi    文件:MoshiParamConverterFactoryTest.java   
@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);
}
项目:jax-rs-moshi    文件:MoshiParamConverterFactoryTest.java   
@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);
}
项目:grooves    文件:DateParameterConverterProvider.java   
@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;
}
项目:minijax    文件:MinijaxProviders.java   
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;
}
项目:factcast    文件:JsonParamConverterProvider.java   
@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;
}
项目:PiCameraProject    文件:LocalDateTimeConverterProvider.java   
@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;
}
项目:microprofile-rest-client    文件:TestParamConverterProvider.java   
@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;
}
项目:bootstrap    文件:UnixTimestampParameterHandler.java   
@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;
}
项目:eplmp    文件:CustomConverterProvider.java   
@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;
}
项目:mentor    文件:GuiceParamConverterProvider.java   
@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();

}
项目:starwizard    文件:JavaTimeParamConverterProviderTest.java   
@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)));
}
项目:starwizard    文件:JavaTimeParamConverterProviderTest.java   
@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));
}
项目:Plume    文件:TimeParamProvider.java   
@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;
}
项目:swiftproxy    文件:OptionalParamProvider.java   
@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;
}
项目:hawkular-client-java    文件:ConvertersProvider.java   
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();
}
项目:openmeetings    文件:OmParamConverterProvider.java   
@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;
}
项目:tinytypes    文件:TinyTypesParamProvider.java   
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) {
    if (MetaTinyTypes.isTinyType(rawType)) {
        return new TinyTypesParamConverter<>(rawType);
    }
    return null;
}
项目:syncope    文件:DateParamConverterProvider.java   
@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;
}
项目:hawkular-metrics    文件:ConvertersProvider.java   
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();
}
项目:dropwizard-java8    文件:MyMessageParamConverterProvider.java   
@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;
}
项目:Larissa    文件:AgentStringReaderProvider.java   
@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;
}
项目:Larissa    文件:DateParamConverterProvider.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ParamConverter getConverter(Class arg0, Type arg1, Annotation[] arg2) {
    if (arg1.equals(Date.class)) {
        return new DateParamConverter();
    } else {
        return null;
    }
}
项目:tomee    文件:RESTService.java   
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);
}
项目:jax-rs-moshi    文件:MoshiParamConverterFactoryTest.java   
@Test public void noAnnotationReturnsNull() {
  ParamConverter<String> converter =
      provider.getConverter(String.class, String.class, new Annotation[0]);
  assertNull(converter);
}
项目:minijax    文件:UuidParamConverterProvider.java   
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
    return rawType == UUID.class ? ((ParamConverter<T>) getConverter()) : null;
}
项目:microprofile-rest-client    文件:MultiTypedProvider.java   
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    return null;
}
项目:openNaEF    文件:ToTransactionId.java   
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    return TransactionId.W.class.isAssignableFrom(rawType) ? (ParamConverter<T>) INSTANCE : null;
}
项目:openNaEF    文件:ToDateTime.java   
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    return Date.class.isAssignableFrom(rawType) ? (ParamConverter<T>) INSTANCE : null;
}
项目:hawkular-client-java    文件:ConvertersProvider.java   
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    return (ParamConverter<T>) paramConverters.get(rawType);
}
项目:tinytypes    文件:TinyTypesParamProviderTest.java   
@Test
public void yieldsNullWhenTypeIsNotATinyType() {
    final Class<?> type = null;
    final ParamConverter<?> got = new TinyTypesParamProvider().getConverter(type, null, null);
    Assert.assertNull(got);
}
项目:tinytypes    文件:TinyTypesParamProviderTest.java   
@Theory
public void yieldsParamConverterForAnyKindOfTinyType(Class<?> tinyType) {
    final ParamConverter<?> got = new TinyTypesParamProvider().getConverter(tinyType, null, null);
    Assert.assertNotNull(got);

}
项目:hawkular-metrics    文件:ConvertersProvider.java   
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    return (ParamConverter<T>) paramConverters.get(rawType);
}
项目:minijax    文件:MinijaxApplication.java   
/**
 * Converts a parameter to a type.
 *
 * @param <T>         the supported Java type convertible to/from a {@code String} format.
 * @param str         The parameter string contents.
 * @param c           the raw type of the object to be converted.
 * @param annotations an array of the annotations associated with the convertible
 *                    parameter instance. E.g. if a string value is to be converted into a method parameter,
 *                    this would be the annotations on that parameter as returned by
 *                    {@link java.lang.reflect.Method#getParameterAnnotations}.
 * @return            the newly created instance of {@code T}.
 */
public <T> T convertParamToType(final String str, final Class<T> c, final Annotation[] annotations) {
    final ParamConverter<T> converter = providers.getParamConverter(c, null, annotations);
    if (converter != null) {
        return converter.fromString(str);
    }

    // Try default primitive converters
    return convertStringToType(str, c);
}