Rectangle 27 1

The converter that the error is complaining about is a JPA AttributeConverter. A GrantedAuthority is not a JPA entity, so you need a way to map it to a database column. You have 2 options:

spring - Getting error "No converter found capable of converting from ...

java spring spring-mvc spring-boot
Rectangle 27 1

No converter found for return value of type: class java.lang.String

It says that the MVC doesn't know which converter use to return the REST response from this service. to use the default converter which are available in spring.

Please add an annotation @ResposeBody in the method signature.

string - MessageTemplate cause no converter found exception in MVC con...

string spring spring-mvc converter
Rectangle 27 6

The problem is that value 9962287970 is out of range for type Integer.

Integer.MAX_VALUE < 9962287970
private Integer phone;
private Long phone;
private String phone;

If you use String you can store other chars like + to the variable phone.

The defauld value of int is 0 but for Integer it is not zero since it a object, so you have to initialize the value to 0;

you can use Long instead..

also consider changing phonenumber to String as a valid phone number can contain the characters "+" and ";". and they are not easy to store in Integer or long.

Spring MVC - Failed to convert property value of type 'java.lang.Strin...

java spring spring-mvc data-binding
Rectangle 27 1

You have exceeded the integer range so either use Long instead of int or make it of String variable type. After applying the changes don't forget to drop the table.

@Id
@Column
private int student_id;
private String name;
private String age;
private String city;
private String country;
private Long/String phone;
private int hsc;
private int sslc;
private int college;

Spring MVC - Failed to convert property value of type 'java.lang.Strin...

java spring spring-mvc data-binding
Rectangle 27 1

Issue 1. see this "nested exception is java.lang.NumberFormatException: For input string: "9962287970"". Since its beyond the range of int. try change it to String or Long.

Issue 2. In Java, int is a primitive type and it is not considered an object. Only objects can have a null value. As soon as the object of an class initialized all primitives set to their default value which is 0 in case of int.

Spring MVC - Failed to convert property value of type 'java.lang.Strin...

java spring spring-mvc data-binding
Rectangle 27 0

If you are working on an MVC application, please see this Spring Source forum link for how to configure your application context. The details are at the bottom of the thread.

The conversionService class is different with MVC and you need to specify mvc:annotation-driven (even if you are not using annotations).

Spring form binding how to do it ? Cannot convert value of type [java....

java spring spring-mvc
Rectangle 27 0

Im glad you got it sorted anyway. I pulled the project and ran it myself anyway just to take a look and your explanation is correct. You could add this to your log4j.xml if you wanted to get rid of that message from polluting your logs in the future :-)

<logger name="org.springframework.beans.TypeConverterDelegate">
    <level value="error" />
</logger>

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

Spring MVC "No converter found capable of converting from type java.la...

java spring spring-mvc type-conversion
Rectangle 27 0

Turns out this was just me not reading the line above the stack trace properly... missed the fact that the line above the stack was "DEBUG".

In short, the conversion service is unable to convert from a String to a Resource; however, spring falls back on it's PropertyEditor-based conversion which succeeds (I believe this is how String-Resource conversions are done normally).

Example of the full stack was as follows:

DEBUG: org.springframework.beans.TypeConverterDelegate - Original ConversionService attempt failed - ignored since PropertyEditor based conversion eventually succeeded
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.util.ArrayList<?> to type java.util.List<org.springframework.core.io.Resource> for value '[/WEB-INF/css/]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type org.springframework.core.io.Resource
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:168)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:161)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1463)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5198)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:634)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:671)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1840)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type org.springframework.core.io.Resource
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:276)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:171)
    at org.springframework.core.convert.support.CollectionToCollectionConverter.convert(CollectionToCollectionConverter.java:83)
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35)
    ... 40 more

Spring MVC "No converter found capable of converting from type java.la...

java spring spring-mvc type-conversion
Rectangle 27 0

[Failed to convert property value of type [java.lang.String[]] to required type [java.util.List] for property 'tags';

How are you handling the object at your controller. You must be accepting java.util.List in the controller handler method whereas the actual object passed is String[]. Try handling it as String[] and convert it to List in you controller.

EDIT: With regards to your comment, I suspected something of that sort. The tags are passed from jsp in form of String[] tag and you are catching a Restaurant object which would need a List and hence the error. Try the following

public ModelAndView myrestaurantadd(HttpServletRequest request, HttpServletResponse response, Restaurant restaurant, String[] tags) throws Exception {
//Convert the String array into List<Tag> and set this list in the restaurant object
//Note that the Restaurant object obtained as the method argument with contain a null tag list, so you would need to set the tag list before saving
//Save the Restaurant object now
}

hibernate - Spring MVC ManyToMany in MultipleSelect - Stack Overflow

hibernate spring-mvc many-to-many
Rectangle 27 0

2012-06-26 12:41:55,215 DEBUG DefaultHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<Resource<java.lang.Object>> StatisticsController.getStats(java.util.Date)]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date]: no matching editors or conversion strategy found
public ResponseEntity<Resource<Object>> getStats(@RequestParam Date fromDate)

indicates that date support requires JODA time which we didn't want. So I tried to add my own converter (that implements Converter) to ConversionServiceFactoryBean

<bean id="conversionService"
      class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="MyStringToDateConverter"/>
        </list>
    </property>
</bean>

and also bound this to the mvc-annotation driven tag:

<mvc:annotation-driven  conversion-service="conversionService"/>

But I never got my converter to kick in. I always got "no matching editors or conversion strategy found".

As indicated above I was hoping to use the Spring MVC 3.x style of conversion service but I had to go for the workaround with the old approach with init binder.

/**
 * I would claim this is should not be needed in Spring 3.x with ConversionServiceFactoryBean
 * @param binder
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}

java - Why isn't spring using my Converter? - Stack Over...

java spring
Rectangle 27 0

For my opinion you've encounterd next situation here. When Spring trying to deserialize Employee entity which was received in addNewHandle it found property department of type of String but in target entity it has Department type, then, because you have no conversion regsieterd for such kind of conversion, it fails. So, to solve this issues you can implement own converter (Converter) that gets String and returns Department and regsiter it in conversionService or you can implement own JSON deserializing strategy by overriding Jackson JsonDeserializer and annotating department property with @JsonDeserialize(using=<your Jacson custom deserializer>.class). Hope this helps.

JSON has no place here. This is a form and the <input> elements will be url-encoded form parameters.

I don't recommend doing this in a Converter. You would probably want to retrieve the Department and create the Employee in the same transaction. It would be hard to do this if you retrieved the Department in a Converter.

While Spring deserialize form into target entity, it creates target entity object and then iterates overtform properties and trying set appropriate fields in target entity object. While setting target entity object field Spring try to convert from source form property value to target field value by means of type conversion and can use appropriate Converter. Thus, we don't need Converter for whole Employee entity, but we need Converter for department property. Correct me if i'm wrong. Thanks in advance.

That is correct. In this case, the Employee is a new object, not yet persisted. But we can assume that the Department exists in persistent storage and that's the one OP is referring to.

java - How to receive complex objects in spring 3.2 mvc? - Stack Overf...

java spring-mvc data-binding
Rectangle 27 0

You have to let Spring know how to convert the return Object by you exception handler so it can write to HTTP response. Lets say "ErrorTO" is a JAXB object and then returned content type is application/xml you should create a HandlerExceptionResolver in your application context and configure a message converter that support application/xml content type (e.g. org.springframework.http.converter.xml.MarshallingHttpMessageConverter). here is an example:

<bean id="outboundExceptionAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
    <property name="messageConverters">
      <util:list>
        <ref bean="marshallingHttpMessageConverter"/>
      </util:list>
    </property>
  </bean>

  <bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    <property name="marshaller" ref="jaxb2Marshaller" />
    <property name="unmarshaller" ref="jaxb2Marshaller" />
  </bean>

  <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPath" value="com.acme" />
  </bean>

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

java - Can a Spring MVC exception handler ONLY support return type of ...

java spring spring-mvc
Rectangle 27 0

You basically have to provide a Converter.

<mvc:annotation-driven conversion-service="applicationConversionService"/>
public class ApplicationConversionServiceFactoryBean
    extends FormattingConversionServiceFactoryBean {

  @Autowired
  TypeOfPatientService typeOfPatientService;

  @Override
  protected void installFormatters(FormatterRegistry registry) {
    registry.addConverter(getStringToTypeOfPatientConverter());
    super.installFormatters(registry);
  }

  public Converter<String, TypeOfPatient> getStringToTypeOfPatientConverter() {
    return new Converter<String, TypeOfPatient>() {
      @Override
      public TypeOfPatient convert(String id) {
        return typeOfPatientService.findTypeOfPatient(Long.parseLong(id));
      }
    };
  }
}

hey I added conversion service.. <mvc:annotation-driven conversion-service="applicationConversionService"/> and I have a class named ApplicationConversionServiceFactoryBean

thanks a lot.. let me try in your ways..

spring - How to resolve this message -Failed to convert property value...

spring java-ee spring-mvc spring-roo
Rectangle 27 0

For anyone interested I found a solution in the Spring documentation. I had to create a class which would handle the conversion from String to Role and register it. This has to make a trip to the database to create the Role object but I don't see another way of handling it.

import javax.inject.Inject;

import org.springframework.core.convert.converter.Converter;

import com.everesttech.recruiting.searchtool.dao.RoleDao;
import com.everesttech.recruiting.searchtool.entity.Role;

final class StringToRole implements Converter<String, Role> {

@Inject
RoleDao roleDao;

@Override
public Role convert(String source) {
    return roleDao.find(Long.parseLong(source));
    }
}
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>

<bean id="conversionService"
  class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="com.examplecompany.exampleapp.example.converter.StringToRole"/>
        </list>
    </property>
</bean>

This works and I'm now able to submit the form with no issues. However now my hibernate validations are not appearing on the JSP when the User object does not meet the validation requirements. As an example First Name has a @NotBlank annotation. I can see that is being detected and I'm logging it. However they are not appearing on the jsp in the form:error tags. If anyone knows how to solve that issue please let me know.

jsp - Spring Forms Bind Exception - IllegalStateException: Cannot conv...

java jsp spring-mvc jstl spring-form
Rectangle 27 0

When you register a PropertyEditor in application context, you are providing the converter from String to some type, in your case the JodaTime type. The bean holding the type, (Contact) don't matter. The application context will use your ContactPropertyEditor editor any time that need to set a property of type JodaTime as String on any bean.

So ContactPropertyEdit it's a bad name. It should be JodaTimePropertyEditor.

If you want a real ContactPropertyEditor, it should convert Strings to Contacts. For example:

<bean id="someBeanHoldingAContact" class="someBeanClass">
<property name="contact" value="Hendrix, Jimi, 1942-11-27, http://www.jimihendrix.com" />
</bean>

and the ContactPropertyEditor should use the string value to create the contact.

org.springframework.beans.BeanWrapperImp

-Thanks. I get it now. So this is like a global editor. Any bean that is using JodaTime will be affected. There is no way do it selectively. Say I only want to apply propertyEditor on a specific Bean only.

No, the container don't check the target class when looking for property editors. But you could implement the conversion in the bean itself or inject the object returned by other bean method deployed in the container.

How does Spring PropertyEditor know which Class propert to convert - S...

spring propertyeditor
Rectangle 27 0

Your error is explained in the stacktrace : Failed to convert property value of type 'java.lang.String' to required type '.model.TypeSites' for property 'siteesTypeSite';

The value in the dropbox is a string and you are trying to match a TypeSites.

I suppose your TypeSites is an Enum. If that's the case just create a function to find the matched value based on the string returned by the dropdown.

<select ng-model="sites.siteesTypeSite"
            name="siteesTypeSiteName"
            ng-options="typesites.typeSite as typesites.typeSite for     typesites in page.source" >
            <option value="">-- Select Type site --</option>
</select>

Create a field siteesTypeSiteName and update your dropbox like I did. Then use the function to get the linked TypeSites.

TypeSites
Many-to-one
private TypeSites     siteesTypeSite

Ok the idea is still the same: in your list you can't return a TypeSites but you can return string, integer... Your TypeSites should have an id in the database then do something like <option value="typeSiteId"> typeSiteName </option> and use a function to get a TypeSites by its id

ng-options="typesites as typesites.typeSite for typesites in page.source "
now Invalid property 'siteesTypeSite[idTypeSite]' of bean class [model.Sites]:Property referenced in indexed property path 'siteesTypeSite[idTypeSite]' is neither an array nor a List nor a Map; returned value was [8]

json - submit dropdown angularjs spring MVC - Stack Overflow

json angularjs spring-mvc data-binding restful-url
Rectangle 27 0

For my opinion you've encounterd next situation here. When Spring trying to deserialize Employee entity which was received in addNewHandle it found property department of type of String but in target entity it has Department type, then, because you have no conversion regsieterd for such kind of conversion, it fails. So, to solve this issues you can implement own converter (Converter) that gets String and returns Department and regsiter it in conversionService or you can implement own JSON deserializing strategy by overriding Jackson JsonDeserializer and annotating department property with @JsonDeserialize(using=<your Jacson custom deserializer>.class). Hope this helps.

JSON has no place here. This is a form and the <input> elements will be url-encoded form parameters.

I don't recommend doing this in a Converter. You would probably want to retrieve the Department and create the Employee in the same transaction. It would be hard to do this if you retrieved the Department in a Converter.

While Spring deserialize form into target entity, it creates target entity object and then iterates overtform properties and trying set appropriate fields in target entity object. While setting target entity object field Spring try to convert from source form property value to target field value by means of type conversion and can use appropriate Converter. Thus, we don't need Converter for whole Employee entity, but we need Converter for department property. Correct me if i'm wrong. Thanks in advance.

That is correct. In this case, the Employee is a new object, not yet persisted. But we can assume that the Department exists in persistent storage and that's the one OP is referring to.

java - How to receive complex objects in spring 3.2 mvc? - Stack Overf...

java spring-mvc data-binding
Rectangle 27 0

Spring 3 introduced the Converter SPI which makes this quite easy. Have a look at 6.5 in the documentation

Taking source from the docs and putting in your country, you would do something like

package my.converter;

final class StringToCountry implements Converter<String, Country> {
    public Country convert(String source) {
        return // whatever you do to get a country from your string
    }
}

Then in the xml config you would configure the converter

<bean id="conversionService"
      class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="my.converter.StringToCountry"/>
        </list>
    </property>
</bean>

As GriffeyDog pointed out, you may want to put the country id in for the select path so you can get the Country by ID or something instead of whatever is returned by toString() of your Country object.

Spring form binding how to do it ? Cannot convert value of type [java....

java spring spring-mvc
Rectangle 27 0

I Googled the error and found this link.

If it's all ok on code, maybe the JVMs are running with diferent locale configuration.

Much appreciate the reply, so it is the java compiler which build the war file? or the compiler tied to JBoss?

Could you please give more specific information from your experience which java version works and which don't?

@Dreamer it's about the war file build and the running JVM. I will try to locate the code where the same issue occurred, so I can give you more detail.

@Dreamer I can't find the code. But I remember what we done to solve. Change the line where you get "orderDate" to get has String and then convert to Date.

spring - Failed to convert from type java.lang.String to type java.uti...

java spring java-ee jboss ejb
Rectangle 27 0

I just had the error with Spring 4.1.1 and the same definition of FormattingConversionServiceFactoryBean.

Hiding logs won't resolve the issue... and in my opinion, it's not a viable solution, especially for production.

<set></set>
<list></list>

Spring MVC "No converter found capable of converting from type java.la...

java spring spring-mvc type-conversion