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


Java GenericConversionService.addConverter方法代码示例

本文整理汇总了Java中org.springframework.core.convert.support.GenericConversionService.addConverter方法的典型用法代码示例。如果您正苦于以下问题:Java GenericConversionService.addConverter方法的具体用法?Java GenericConversionService.addConverter怎么用?Java GenericConversionService.addConverter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.convert.support.GenericConversionService的用法示例。


在下文中一共展示了GenericConversionService.addConverter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: safeConversionService

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
private static GenericConversionService safeConversionService() {
    final GenericConversionService converter = new GenericConversionService();
    converter.addConverter(Object.class, byte[].class, new SerializingConverter());

    final DeserializingConverter byteConverter = new DeserializingConverter();
    converter.addConverter(byte[].class, Object.class, (byte[] bytes) -> {
        try {
            return byteConverter.convert(bytes);
        } catch (SerializationFailedException e) {
            LOG.error("Could not extract attribute: {}", e.getMessage());
            return null;
        }
    });

    return converter;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:HttpSessionConfig.java

示例2: addDateConverters

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
private static void addDateConverters(GenericConversionService conversionService) {

		conversionService.addConverter(Date.class, String.class, new Converter<Date, String>() {
			@Override
			public String convert(Date dateVal) {
				return ValueConversionUtil.dateToIsoString(dateVal);
			}
		});
		conversionService.addConverter(String.class, Date.class, blankConverter(new Converter<String, Date>() {
			@Override
			public Date convert(String stringVal) {
				return ValueConversionUtil.isoStringToDate(stringVal);
			}
		}));

	}
 
开发者ID:innodev-au,项目名称:wmboost-data,代码行数:17,代码来源:ConversionServiceUtils.java

示例3: customConversion

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Test
public void customConversion() throws Exception {
	DefaultMessageHandlerMethodFactory instance = createInstance();
	GenericConversionService conversionService = new GenericConversionService();
	conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() {
		@Override
		public String convert(SampleBean source) {
			return "foo bar";
		}
	});
	instance.setConversionService(conversionService);
	instance.afterPropertiesSet();

	InvocableHandlerMethod invocableHandlerMethod =
			createInvocableHandlerMethod(instance, "simpleString", String.class);

	invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build());
	assertMethodInvocation(sample, "simpleString");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultMessageHandlerMethodFactoryTests.java

示例4: test

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Test
@Deprecated
public void test() throws Exception {
	AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
	ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
	GenericConversionService service = new DefaultConversionService();
	service.addConverter(new ColorConverter());
	binder.setConversionService(service);
	adapter.setWebBindingInitializer(binder);
	Spr7766Controller controller = new Spr7766Controller();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/colors");
	request.setPathInfo("/colors");
	request.addParameter("colors", "#ffffff,000000");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, controller);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:Spr7766Tests.java

示例5: testCustomConverter

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Test
public void testCustomConverter() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	GenericConversionService conversionService = new DefaultConversionService();
	conversionService.addConverter(new Converter<String, Float>() {
		@Override
		public Float convert(String source) {
			try {
				NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
				return nf.parse(source).floatValue();
			}
			catch (ParseException ex) {
				throw new IllegalArgumentException(ex);
			}
		}
	});
	lbf.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("testBean", bd);
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:DefaultListableBeanFactoryTests.java

示例6: noDelegateMapConversion

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Test
public void noDelegateMapConversion() {
	GenericConversionService conversionService = new GenericConversionService();
	GenericMapConverter mapConverter = new GenericMapConverter(conversionService);
	conversionService.addConverter(mapConverter);

	@SuppressWarnings("unchecked")
	Map<String, String> result = conversionService.convert("foo = bar, wizz = jogg", Map.class);
	assertThat(result, hasEntry("foo", "bar"));
	assertThat(result, hasEntry("wizz", "jogg"));

	assertThat(
			conversionService.canConvert(TypeDescriptor.valueOf(String.class), TypeDescriptor.map(Map.class,
					TypeDescriptor.valueOf(GenericMapConverterTests.class), TypeDescriptor.valueOf(Integer.class))),
			is(false));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:17,代码来源:GenericMapConverterTests.java

示例7: registerConvertersIn

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Register custom converters within given {@link org.springframework.core.convert.support.GenericConversionService}
 *
 * @param conversionService must not be null
 */
public void registerConvertersIn(GenericConversionService conversionService) {
	Assert.notNull(conversionService);

	for (Object converter : converters) {
		if (converter instanceof Converter) {
			conversionService.addConverter((Converter<?, ?>) converter);
		} else if (converter instanceof ConverterFactory) {
			conversionService.addConverterFactory((ConverterFactory<?, ?>) converter);
		} else if (converter instanceof GenericConverter) {
			conversionService.addConverter((GenericConverter) converter);
		} else {
			throw new IllegalArgumentException("Given object '" + converter
					+ "' expected to be a Converter, ConverterFactory or GenericeConverter!");
		}
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:22,代码来源:CustomConversions.java

示例8: registerConvertersIn

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Populates the given {@link GenericConversionService} with the converters registered.
 *
 * @param conversionService the service to register.
 */
public void registerConvertersIn(final GenericConversionService conversionService) {
  for (Object converter : converters) {
    boolean added = false;

    if (converter instanceof Converter) {
      conversionService.addConverter((Converter<?, ?>) converter);
      added = true;
    }

    if (converter instanceof ConverterFactory) {
      conversionService.addConverterFactory((ConverterFactory<?, ?>) converter);
      added = true;
    }

    if (converter instanceof GenericConverter) {
      conversionService.addConverter((GenericConverter) converter);
      added = true;
    }

    if (!added) {
      throw new IllegalArgumentException("Given set contains element that is neither Converter nor ConverterFactory!");
    }
  }
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:30,代码来源:CustomConversions.java

示例9: registerConvertersIn

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Register custom converters within given {@link GenericConversionService}
 * 
 * @param conversionService must not be null
 */
public void registerConvertersIn(GenericConversionService conversionService) {
	Assert.notNull(conversionService);

	for (Object converter : converters) {
		if (converter instanceof Converter) {
			conversionService.addConverter((Converter<?, ?>) converter);
		} else if (converter instanceof ConverterFactory) {
			conversionService.addConverterFactory((ConverterFactory<?, ?>) converter);
		} else if (converter instanceof GenericConverter) {
			conversionService.addConverter((GenericConverter) converter);
		} else {
			throw new IllegalArgumentException("Given object '" + converter
					+ "' expected to be a Converter, ConverterFactory or GenericeConverter!");
		}
	}
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:22,代码来源:CustomConversions.java

示例10: setupProcessor

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Sets up the bean post processor and conversion service
 *
 * @param beans - The bean factory for the the dictionary beans
 */
public static void setupProcessor(DefaultListableBeanFactory beans) {
    try {
        // UIF post processor that sets component ids
        BeanPostProcessor idPostProcessor = ComponentBeanPostProcessor.class.newInstance();
        beans.addBeanPostProcessor(idPostProcessor);
        beans.setBeanExpressionResolver(new StandardBeanExpressionResolver() {
            @Override
            protected void customizeEvaluationContext(StandardEvaluationContext evalContext) {
                try {
                    evalContext.registerFunction("getService", ExpressionFunctions.class.getDeclaredMethod("getService", new Class[]{String.class}));
                } catch(NoSuchMethodException me) {
                    LOG.error("Unable to register custom expression to data dictionary bean factory", me);
                }
            }
        });

        // special converters for shorthand map and list property syntax
        GenericConversionService conversionService = new GenericConversionService();
        conversionService.addConverter(new StringMapConverter());
        conversionService.addConverter(new StringListConverter());

        beans.setConversionService(conversionService);
    } catch (Exception e1) {
        throw new DataDictionaryException("Cannot create component decorator post processor: " + e1.getMessage(),
                e1);
    }
}
 
开发者ID:kuali,项目名称:rice,代码行数:33,代码来源:DataDictionary.java

示例11: setupProcessor

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Sets up the bean post processor and conversion service
 *
 * @param beans - The bean factory for the the dictionary beans
 */
public static void setupProcessor(KualiDefaultListableBeanFactory beans) {
    try {
        // UIF post processor that sets component ids
        BeanPostProcessor idPostProcessor = ComponentBeanPostProcessor.class.newInstance();
        beans.addBeanPostProcessor(idPostProcessor);
        beans.setBeanExpressionResolver(new StandardBeanExpressionResolver());

        // special converters for shorthand map and list property syntax
        GenericConversionService conversionService = new GenericConversionService();
        conversionService.addConverter(new StringMapConverter());
        conversionService.addConverter(new StringListConverter());

        beans.setConversionService(conversionService);
    } catch (Exception e1) {
        throw new DataDictionaryException("Cannot create component decorator post processor: " + e1.getMessage(),
                e1);
    }
}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:24,代码来源:DataDictionary.java

示例12: getConversionService

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
protected GenericConversionService getConversionService(Workbook workbook,
		Map<String, Map<String, GenericEntity<Long, ?>>> idsMapping) {
	GenericConversionService service = new GenericConversionService();

	GenericEntityConverter genericEntityConverter = new GenericEntityConverter(importDataDao, workbook,
			new HashMap<Class<?>, Class<?>>(0), idsMapping);
	genericEntityConverter.setConversionService(service);
	service.addConverter(genericEntityConverter);

	service.addConverter(new ProjectConverter());
	service.addConverter(new ArtifactConverter());
	service.addConverter(new ExternalLinkWrapperConverter());

	DefaultConversionService.addDefaultConverters(service);

	return service;
}
 
开发者ID:openwide-java,项目名称:artifact-listener,代码行数:18,代码来源:ProjectImportDataServiceImpl.java

示例13: setUp

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Before
public void setUp() throws NoSuchFieldException {
	GenericConversionService genericConversionService = new GenericConversionService();

	genericConversionService.addConverter(new Converter<String, Integer>() {
		@Override
		public Integer convert(String source) {
			if (0 == source.length()) {
				return null;
			}
			return NumberUtils.parseNumber(source, Integer.class);
		}
	});

	Mockito.when(conversionServiceFactoryBean.getObject()).thenReturn(genericConversionService);

	mockCartEntry();
	mockProduct();
}
 
开发者ID:cpollet,项目名称:jixture,代码行数:20,代码来源:TestFileFixtureTransformer.java

示例14: registerConvertersIn

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
/**
 * Populates the given {@link GenericConversionService} with the convertes registered.
 *
 * @param conversionService
 */
public void registerConvertersIn(GenericConversionService conversionService) {

    for (Object converter : converters) {

        boolean added = false;

        if (converter instanceof Converter) {
            conversionService.addConverter((Converter<?, ?>) converter);
            added = true;
        }

        if (converter instanceof ConverterFactory) {
            conversionService.addConverterFactory((ConverterFactory<?, ?>) converter);
            added = true;
        }

        if (converter instanceof GenericConverter) {
            conversionService.addConverter((GenericConverter) converter);
            added = true;
        }

        if (!added) {
            throw new IllegalArgumentException(
                    "Given set contains element that is neither Converter nor ConverterFactory!");
        }
    }
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:33,代码来源:CustomConversions.java

示例15: testCustomDocFactory

import org.springframework.core.convert.support.GenericConversionService; //导入方法依赖的package包/类
@Test
public void testCustomDocFactory() {
	final Values customIData =  new Values(new Object[][] {{"key1", "Hello!"}});
	
	GenericConversionService conversionService = new GenericConversionService();
	Converter<String, MyClass> converter = new Converter<String, MyClass>() {
		public MyClass convert(String source) {
			return new MyClass(source);
		};
	};
	conversionService.addConverter(String.class, MyClass.class, converter );
	DocumentFactoryBuilder docFactBuilder = new DocumentFactoryBuilder();
	docFactBuilder.setConversionService(conversionService);
	docFactBuilder.setDirectIDataFactory(new DirectIDataFactory() {
		
		@Override
		public IData create() {				
			return customIData;
		}
	});
	
	DocumentFactory docFact = docFactBuilder.build();
	Document document = docFact.create();
	
	// Confirm custom IData is the one that has been created
	assertSame(document.getIData(), customIData);
	
	// Confirm the conversion service we created is used
	assertEquals("Hello!", document.entry("key1", MyClass.class).getVal().getText());
	
}
 
开发者ID:innodev-au,项目名称:wmboost-data,代码行数:32,代码来源:DocumentFactoryBuilderTest.java


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