当前位置: 首页>>代码示例>>Java>>正文


Java ParamConverter类代码示例

本文整理汇总了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;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:24,代码来源:DummyParamProvider.java

示例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);
	
}
 
开发者ID:vsite-hr,项目名称:mentor,代码行数:23,代码来源:ResourceModule.java

示例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;
}
 
开发者ID:geekmj,项目名称:jersey-jax-rs-examples,代码行数:25,代码来源:DateParamModelConvertorProvider.java

示例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;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:22,代码来源:CommonTypesParamConverterProvider.java

示例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;
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:11,代码来源:MoshiParamConverterFactory.java

示例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);
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:8,代码来源:MoshiParamConverterFactoryTest.java

示例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);
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:11,代码来源:MoshiParamConverterFactoryTest.java

示例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);
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:12,代码来源:MoshiParamConverterFactoryTest.java

示例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;
}
 
开发者ID:rahulsom,项目名称:grooves,代码行数:10,代码来源:DateParameterConverterProvider.java

示例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;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxProviders.java

示例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;
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:12,代码来源:JsonParamConverterProvider.java

示例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;
}
 
开发者ID:erikcostlow,项目名称:PiCameraProject,代码行数:9,代码来源:LocalDateTimeConverterProvider.java

示例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;
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:8,代码来源:TestParamConverterProvider.java

示例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;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:16,代码来源:UnixTimestampParameterHandler.java

示例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;
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:10,代码来源:CustomConverterProvider.java


注:本文中的javax.ws.rs.ext.ParamConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。