Package org.springframework.core.convert

Examples of org.springframework.core.convert.ConversionService


        assertEquals(true, found);
    }
    @Test
    public void injectionForConversionService() {
        final Config config = assertInjected("-conversion");
        final ConversionService conversionService = config.neo4jTemplate.getConversionService();
        assertEquals(true, conversionService.canConvert(Enum.class,String.class));
        assertEquals(true, conversionService.canConvert(Config.class, Integer.class));
    }
View Full Code Here


  @Test
  public void shouldReturnDefaultConversionService() {
    // given
    MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
    // when
    ConversionService conversionService = converter.getConversionService();
    // then
    assertThat(conversionService, is(notNullValue()));
  }
View Full Code Here

    if (idProperty == null) {
      return;
    }

    ConversionService service = mongoConverter.getConversionService();
    Object idValue = BeanWrapper.create(entity, service).getProperty(idProperty, Object.class);

    if (idValue == null && !MongoSimpleTypes.AUTOGENERATED_ID_TYPES.contains(idProperty.getType())) {
      throw new InvalidDataAccessApiUsageException(String.format(
          "Cannot autogenerate id of type %s for entity of type %s!", idProperty.getType().getName(), entity.getClass()
View Full Code Here

    if (idProp == null) {
      return;
    }

    ConversionService conversionService = mongoConverter.getConversionService();
    BeanWrapper<Object> wrapper = BeanWrapper.create(savedObject, conversionService);

    Object idValue = wrapper.getProperty(idProp, idProp.getType());

    if (idValue != null) {
View Full Code Here

        } else if (parameter.hasParameterAnnotation(WidgetPref.class)) {
            value = getWidgetPrefValue(parameter, webRequest);
        }
        //
        if (value != null) {
            ConversionService conversionService = (ConversionService) webRequest.getAttribute(ConversionService.class.getName(), WebRequest.SCOPE_REQUEST);
            if (conversionService.canConvert(value.getClass(), parameter.getParameterType())) {
                value = conversionService.convert(value, parameter.getParameterType());
            } else {
                throw new ConverterNotFoundException(TypeDescriptor.forObject(value), TypeDescriptor.valueOf(parameter.getParameterType()));
            }
        }
        //
View Full Code Here

        "ReverseDataBinder.reverseBind can only be used with a DataBinder that has a target object");

    MutablePropertyValues rtn = new MutablePropertyValues();
    BeanWrapper target = PropertyAccessorFactory.forBeanPropertyAccess(this.dataBinder.getTarget());

    ConversionService conversionService = this.dataBinder.getConversionService();
    if (conversionService != null) {
      target.setConversionService(conversionService);
    }

    PropertyDescriptor[] propertyDescriptors = target.getPropertyDescriptors();
View Full Code Here

    if (editor != null) {
      return editor;
    }

    // Use the conversion service
    ConversionService conversionService = this.dataBinder.getConversionService();
    if (conversionService != null) {
      if (conversionService.canConvert(TypeDescriptor.valueOf(String.class), typeDescriptor)) {
        return new ConvertingPropertyEditorAdapter(conversionService, typeDescriptor);
      }
    }

    // Fall back to default editors
View Full Code Here

    }


  @Override
    public boolean accept(final Neo4jPersistentProperty property) {
        final ConversionService conversionService = getConversionService();
        return property.isSerializablePropertyField(conversionService);
    }
View Full Code Here

      @Override
      protected Object createInstance(final ScalarNode node, final CompactData data)
          throws Exception {
        Class<?> clazz = getClassForName(data.getPrefix());
        Constructor<?>[] constructors = clazz.getDeclaredConstructors();
        ConversionService conversionService = applicationContext.getBean(ConversionService.class);

        // find best matching constructor
        for (Constructor<?> constructor : constructors) {
          Class<?>[] parameterTypes = constructor.getParameterTypes();
          if (parameterTypes.length == data.getArguments().size()) {
            boolean found = true;
            int p = 0;
            Object[] args = new Object[parameterTypes.length];
            while (found && p < parameterTypes.length) {
              Class<?> parameterType = parameterTypes[p];
              boolean canConvert = conversionService.canConvert(String.class, parameterType);
              if (canConvert) {
                args[p] = conversionService.convert(data.getArguments().get(p), parameterType);
              }
              found &= canConvert;
              p++;
            }
            if (found) {
View Full Code Here

  }

  public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (converter == null && beanFactory instanceof ConfigurableBeanFactory) {
      ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory;
      ConversionService conversionService = cFB.getConversionService();

      converter = (conversionService != null ? new Converter(conversionService) : new Converter(cFB.getTypeConverter()));
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.ConversionService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.