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


Java ConverterNotFoundException类代码示例

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


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


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