本文整理汇总了Java中javax.ws.rs.ext.ParamConverter类的典型用法代码示例。如果您正苦于以下问题:Java ParamConverter类的具体用法?Java ParamConverter怎么用?Java ParamConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParamConverter类属于javax.ws.rs.ext包,在下文中一共展示了ParamConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例2: configure
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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);
}
示例3: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例4: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例5: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例6: differentJsonAnnotationReturnsNull
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@Test public void differentJsonAnnotationReturnsNull() {
ParamConverter<String> converter =
provider.getConverter(String.class, String.class, new Annotation[] {
Annotations.other()
});
assertNull(converter);
}
示例7: jsonAnnotationReturnsConverterClass
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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);
}
示例8: jsonAnnotationReturnsConverterParameterized
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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);
}
示例9: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例10: getParamConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
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;
}
示例11: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例12: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例13: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例14: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}
示例15: getConverter
import javax.ws.rs.ext.ParamConverter; //导入依赖的package包/类
@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;
}