• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ConverterNotFoundException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.core.convert.ConverterNotFoundException的典型用法代码示例。如果您正苦于以下问题:Java ConverterNotFoundException类的具体用法?Java ConverterNotFoundException怎么用?Java ConverterNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConverterNotFoundException类属于org.springframework.core.convert包,在下文中一共展示了ConverterNotFoundException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: scalarMap

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void scalarMap() throws Exception {
	Map<String, String> map = new HashMap<String, String>();
	map.put("1", "9");
	map.put("2", "37");
	TypeDescriptor sourceType = TypeDescriptor.forObject(map);
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarMapTarget"));
	assertTrue(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(map, sourceType, targetType);
	} catch (ConversionFailedException e) {
		assertTrue(e.getCause() instanceof ConverterNotFoundException);
	}
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	Map<Integer, Integer> result = (Map<Integer, Integer>) conversionService.convert(map, sourceType, targetType);
	assertFalse(map.equals(result));
	assertEquals((Integer) 9, result.get(1));
	assertEquals((Integer) 37, result.get(2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MapToMapConverterTests.java


示例2: scalarMapNotGenericSourceField

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void scalarMapNotGenericSourceField() throws Exception {
	Map<String, String> map = new HashMap<String, String>();
	map.put("1", "9");
	map.put("2", "37");
	TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("notGenericMapSource"));
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarMapTarget"));
	assertTrue(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(map, sourceType, targetType);
	} catch (ConversionFailedException e) {
		assertTrue(e.getCause() instanceof ConverterNotFoundException);
	}
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	Map<Integer, Integer> result = (Map<Integer, Integer>) conversionService.convert(map, sourceType, targetType);
	assertFalse(map.equals(result));
	assertEquals((Integer) 9, result.get(1));
	assertEquals((Integer) 37, result.get(2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MapToMapConverterTests.java


示例3: collectionMap

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void collectionMap() throws Exception {
	Map<String, List<String>> map = new HashMap<String, List<String>>();
	map.put("1", Arrays.asList("9", "12"));
	map.put("2", Arrays.asList("37", "23"));
	TypeDescriptor sourceType = TypeDescriptor.forObject(map);
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("collectionMapTarget"));
	assertTrue(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(map, sourceType, targetType);
	} catch (ConversionFailedException e) {
		assertTrue(e.getCause() instanceof ConverterNotFoundException);
	}
	conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	Map<Integer, List<Integer>> result = (Map<Integer, List<Integer>>) conversionService.convert(map, sourceType, targetType);
	assertFalse(map.equals(result));
	assertEquals(Arrays.asList(9, 12), result.get(1));
	assertEquals(Arrays.asList(37, 23), result.get(2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MapToMapConverterTests.java


示例4: collectionMapSourceTarget

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void collectionMapSourceTarget() throws Exception {
	Map<String, List<String>> map = new HashMap<String, List<String>>();
	map.put("1", Arrays.asList("9", "12"));
	map.put("2", Arrays.asList("37", "23"));
	TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("sourceCollectionMapTarget"));
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("collectionMapTarget"));
	assertFalse(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(map, sourceType, targetType);
		fail("Should have failed");
	}
	catch (ConverterNotFoundException ex) {
		// expected
	}
	conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	Map<Integer, List<Integer>> result = (Map<Integer, List<Integer>>) conversionService.convert(map, sourceType, targetType);
	assertFalse(map.equals(result));
	assertEquals(Arrays.asList(9, 12), result.get(1));
	assertEquals(Arrays.asList(37, 23), result.get(2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:MapToMapConverterTests.java


示例5: adaptedCollectionTypesFromSameSourceType

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void adaptedCollectionTypesFromSameSourceType() throws Exception {
	conversionService.addConverter(new MyStringToStringCollectionConverter());

	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericCollection"))));
	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));
	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericCollection"))));
	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
	assertEquals(Collections.singleton("testX"),
			conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));

	try {
		conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("integerCollection")));
		fail("Should have thrown ConverterNotFoundException");
	}
	catch (ConverterNotFoundException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:GenericConversionServiceTests.java


示例6: testAggregateDailyStatistics

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void testAggregateDailyStatistics(){
   try {
      DailyStatistic stat = repository.aggregateDailyStatistics("20140930");
   } catch (ConverterNotFoundException cvnfe){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is working
      // but SpringData cannot convert Fongo Rhino result into Java object
      // ("No converter found capable of converting from type org.mozilla.javascript.UniqueTag to type java.lang.Integer")
   } catch (UncategorizedMongoDbException ume){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is not working
      // ("org.mozilla.javascript.EcmaError: TypeError: Cannot read property "0" from undefined")
   } catch (RuntimeException re){
      // For now, mapReduce in Fongo is experimental. MapReduce execution is working
      // but SpringData cannot convert Fongo Rhino result into Java object
      // ("json can't serialize type : class org.mozilla.javascript.UniqueTag")
   }
}
 
开发者ID:microcks,项目名称:microcks,代码行数:18,代码来源:CustomDailyStatisticRepositoryTest.java


示例7: scalarList

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void scalarList() throws Exception {
	List<String> list = new ArrayList<String>();
	list.add("9");
	list.add("37");
	TypeDescriptor sourceType = TypeDescriptor.forObject(list);
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarListTarget"));
	assertTrue(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(list, sourceType, targetType);
	}
	catch (ConversionFailedException ex) {
		assertTrue(ex.getCause() instanceof ConverterNotFoundException);
	}
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	List<String> result = (List<String>) conversionService.convert(list, sourceType, targetType);
	assertFalse(list.equals(result));
	assertEquals(9, result.get(0));
	assertEquals(37, result.get(1));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:CollectionToCollectionConverterTests.java


示例8: collectionMapSourceTarget

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void collectionMapSourceTarget() throws Exception {
	Map<String, List<String>> map = new HashMap<String, List<String>>();
	map.put("1", Arrays.asList("9", "12"));
	map.put("2", Arrays.asList("37", "23"));
	TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("sourceCollectionMapTarget"));
	TypeDescriptor targetType = new TypeDescriptor(getClass().getField("collectionMapTarget"));
	assertFalse(conversionService.canConvert(sourceType, targetType));
	try {
		conversionService.convert(map, sourceType, targetType);
		fail("Should have failed");
	} catch (ConverterNotFoundException e) {

	}
	conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
	conversionService.addConverterFactory(new StringToNumberConverterFactory());
	assertTrue(conversionService.canConvert(sourceType, targetType));
	@SuppressWarnings("unchecked")
	Map<Integer, List<Integer>> result = (Map<Integer, List<Integer>>) conversionService.convert(map, sourceType, targetType);
	assertFalse(map.equals(result));
	assertEquals(Arrays.asList(9, 12), result.get(1));
	assertEquals(Arrays.asList(37, 23), result.get(2));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:MapToMapConverterTests.java


示例9: handleConverterNotFound

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
private Object handleConverterNotFound(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	if (source == null) {
		assertNotPrimitiveTargetType(sourceType, targetType);
		return null;
	}
	if (sourceType.isAssignableTo(targetType) && targetType.getObjectType().isInstance(source)) {
		return source;
	}
	throw new ConverterNotFoundException(sourceType, targetType);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:GenericConversionService.java


示例10: elementTypesNotConvertible

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test(expected = ConverterNotFoundException.class)
public void elementTypesNotConvertible() throws Exception {
	List<String> resources = new ArrayList<String>();
	resources.add(null);
	resources.add(null);
	TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
	assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:CollectionToCollectionConverterTests.java


示例11: convertFromStreamToArrayNoConverter

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
	Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
	TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs")); ;

	thrown.expect(ConversionFailedException.class);
	thrown.expectCause(is(instanceOf(ConverterNotFoundException.class)));
	this.conversionService.convert(stream, arrayOfLongs);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:StreamConverterTests.java


示例12: encodeToTextCannotConvert

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void encodeToTextCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	thown.expect(EncodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	new MyTextEncoder().encode(myType);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:ConvertingEncoderDecoderSupportTests.java


示例13: encodeToBinaryCannotConvert

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void encodeToBinaryCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	thown.expect(EncodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	new MyBinaryEncoder().encode(myType);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:ConvertingEncoderDecoderSupportTests.java


示例14: decodeFromTextCannotConvert

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void decodeFromTextCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	Decoder.Text<MyType> decoder = new MyTextDecoder();
	assertThat(decoder.willDecode(CONVERTED_TEXT), is(false));
	thown.expect(DecodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	decoder.decode(CONVERTED_TEXT);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ConvertingEncoderDecoderSupportTests.java


示例15: decodeFromBinaryCannotConvert

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void decodeFromBinaryCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(false));
	thown.expect(DecodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	decoder.decode(CONVERTED_BYTES);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ConvertingEncoderDecoderSupportTests.java


示例16: get

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
private <T> T get(String propertyName, Class<T> type, Properties props) throws IllegalArgumentException {
	Validate.notEmpty(propertyName);
	Validate.notNull(type);
	String value = props.getProperty(propertyName);
	if(value == null) {
		throw new IllegalArgumentException();
	}
	try {
		return converter.convert(value, type);
	} catch (IllegalArgumentException | ConversionFailedException | ConverterNotFoundException ex) {
		LOGGER.warn("Invalid type for property: {}, value: {}, reason: {}", propertyName, value, ex.getMessage());
		throw new IllegalArgumentException();
	}
}
 
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:15,代码来源:DefaultProperties.java


示例17: handleConverterNotFound

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
private Object handleConverterNotFound(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	if (source == null) {
		assertNotPrimitiveTargetType(sourceType, targetType);
		return source;
	}
	if (sourceType.isAssignableTo(targetType) && targetType.getObjectType().isInstance(source)) {
		return source;
	}
	throw new ConverterNotFoundException(sourceType, targetType);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:GenericConversionService.java


示例18: elementTypesNotConvertible

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test(expected=ConverterNotFoundException.class)
public void elementTypesNotConvertible() throws Exception {
	List<String> resources = new ArrayList<String>();
	resources.add(null);
	resources.add(null);
	TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
	assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:9,代码来源:CollectionToCollectionConverterTests.java


示例19: converterNotFound

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void converterNotFound() {
	try {
		conversionService.convert("3", Integer.class);
		fail("Should have thrown an exception");
	}
	catch (ConverterNotFoundException e) {
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:10,代码来源:GenericConversionServiceTests.java


示例20: genericConverterDelegatingBackToConversionServiceConverterNotFound

import org.springframework.core.convert.ConverterNotFoundException; //导入依赖的package包/类
@Test
public void genericConverterDelegatingBackToConversionServiceConverterNotFound() {
	conversionService.addConverter(new ObjectToArrayConverter(conversionService));
	assertFalse(conversionService.canConvert(String.class, Integer[].class));
	try {
		conversionService.convert("3,4,5", Integer[].class);
		fail("should have failed");
	}
	catch (ConverterNotFoundException ex) {
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:12,代码来源:GenericConversionServiceTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java User类代码示例发布时间:2022-05-22
下一篇:
Java Description类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap