@Bean public ConversionService webSocketConversionService() { return new GenericConversionService(); }
private static GenericConversionService getConversionService() { GenericConversionService conversionService = new GenericConversionService(); new RedisCustomConversions().registerConvertersIn(conversionService); return conversionService; }
@Test public void testCollectionsEmptyList() throws Exception { CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService()); TypeDescriptor type = new TypeDescriptor(getClass().getField("list")); converter.convert(list, type, TypeDescriptor.valueOf(Class.forName("java.util.Collections$EmptyList"))); }
@SuppressWarnings("rawtypes") private void testCollectionConversionToArrayList(Collection<String> aSource) { Object myConverted = (new CollectionToCollectionConverter(new GenericConversionService())).convert( aSource, TypeDescriptor.forObject(aSource), TypeDescriptor.forObject(new ArrayList())); assertTrue(myConverted instanceof ArrayList<?>); assertEquals(aSource.size(), ((ArrayList<?>) myConverted).size()); }
public AclClassIdUtils() { GenericConversionService genericConversionService = new GenericConversionService(); genericConversionService.addConverter(String.class, Long.class, new StringToLongConverter()); genericConversionService.addConverter(String.class, UUID.class, new StringToUUIDConverter()); this.conversionService = genericConversionService; }
private static GenericConversionService createDefaultConversionService() { GenericConversionService converter = new GenericConversionService(); converter.addConverter(Object.class, byte[].class, new SerializingConverter()); converter.addConverter(byte[].class, Object.class, new DeserializingConverter()); return converter; }
private GenericConversionService createConversionServiceWithBeanClassLoader() { GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(Object.class, byte[].class, new SerializingConverter()); conversionService.addConverter(byte[].class, Object.class, new DeserializingConverter(this.classLoader)); return conversionService; }
@Test public void test_binaryPlusWithTimeConverted() { SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(Time.class, String.class, format::format); StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext(); evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService)); ExpressionState expressionState = new ExpressionState(evaluationContextConverter); Time time = new Time(new Date().getTime()); VariableReference var = new VariableReference("timeVar", -1, -1); var.setValue(expressionState, time); StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\""); OpPlus o = new OpPlus(-1, -1, var, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals(format.format(time) + " is now", value.getValue()); }
GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); GenericConversionService cs = new GenericConversionService(); cs.addConverter(String.class, String.class, String::trim); ac.getBeanFactory().registerSingleton(GenericApplicationContext.CONVERSION_SERVICE_BEAN_NAME, cs);
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
@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"); }
public MappingDocumentDbConverter( MappingContext<? extends DocumentDbPersistentEntity<?>, DocumentDbPersistentProperty> mappingContext) { this.mappingContext = mappingContext; this.conversionService = new GenericConversionService(); }
public MappingDocumentDbConverter( MappingContext<? extends DocumentDbPersistentEntity<?>, DocumentDbPersistentProperty> mappingContext) { this.mappingContext = mappingContext; this.conversionService = new GenericConversionService(); }
public MappingGremlinConverter( MappingContext<? extends GremlinPersistentEntity<?>, GremlinPersistentProperty> context) { this.mappingContext = context; this.conversionService = new GenericConversionService(); }
public MappingDocumentDbConverter( MappingContext<? extends DocumentDbPersistentEntity<?>, DocumentDbPersistentProperty> mappingContext, @Qualifier(Constants.OBJECTMAPPER_BEAN_NAME) ObjectMapper objectMapper) { this.mappingContext = mappingContext; this.conversionService = new GenericConversionService(); this.objectMapper = objectMapper == null ? ObjectMapperFactory.getObjectMapper() : objectMapper; }
private static GenericConversionService getConversionService() { GenericConversionService conversionService = new GenericConversionService(); new RedisCustomConversions().registerConvertersIn(conversionService); return conversionService; }
private ConversionService getDefaultConversionService() { GenericConversionService conversionService = new GenericConversionService(); configureConverters(conversionService); conversionService.addConverter(new NumberConverter()); return conversionService; } }
private void initBeanWrapper(BeanWrapperImpl beanWrapper) { GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(new MultipartFileConverter(beanWrapper)); beanWrapper.setConversionService(conversionService); if (beanFactory != null) { beanFactory.copyRegisteredEditorsTo(beanWrapper); } }
/** * Create a new {@link RelaxedConversionService} instance. * @param conversionService and option root conversion service */ RelaxedConversionService(ConversionService conversionService) { this.conversionService = conversionService; this.additionalConverters = new GenericConversionService(); DefaultConversionService.addDefaultConverters(this.additionalConverters); this.additionalConverters .addConverterFactory(new StringToEnumIgnoringCaseConverterFactory()); this.additionalConverters.addConverter(new StringToCharArrayConverter()); }
@Before public void setUp() throws Exception { Identifiable somePatientID = new Identifiable("id1", new AssigningAuthority("1.3")); someData = SampleData.createDataHandler(); docEntry = SampleData.createDocumentEntry(somePatientID); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(new DataHandlerToByteArrayConverter()); conversionService.addConverter(new ByteArrayToStringConverter()); conversionService.addConverter(new ByteArrayToClinicalDocumentConverter()); conversionService.addConverter(new ByteArrayToDomConverter()); Document.setConversionService(new SpringTypeConverter(conversionService)); }