开发者

ConversionNotSupportedException with similarly named classes

UPDATED: made some wrong assumptions about classes etc. The following occurs now when I have a 'demo' project:

I have two classes, both named 'Company'.

  • One is placed in grails-app/domain/my.classes.domain.Company
  • the other is in src/groovy/my.clazz.Company

The last one has a @Validateable annotation, and the Config.groovy contains grails.validateable.packages = ['my.clazz']

I also have an Account class, in grails-app/domain/my.classes.domain.Account:

package my.classes.domain

import java.io.Serializable;

class Account implements Serializable { Company company }

Then I use the following code (in the bootstrap.groovy):

import my.classes.domain.Company
import my.classes.domain.Account
...
Company company = new Company
Account ac开发者_如何学Cccount = new Account(company: company)

When running this app, the following error is shown:

Caused by: org.springframework.beans.ConversionNotSupportedException: Cannot convert value of type [my.clazz.Company] to required type [my.classes.domain.Company] for property 'company': no matching editors or conversion strategy found
    ... 33 more
Caused by: java.lang.IllegalStateException:
Cannot convert value of type [my.clazz.Company] to required type [my.classes.domain.Company] for property 'company': no matching editors or conversion strategy found

This is a very strange exception, as everything seems to be fine. Some testing proved the following 'hints': This error does NOT occur when I modify the config.groovy to explicitly name the classes (i.e. use grails.validateable.classes = ['my.classes.domain.Company']), This error does NOT occur when I modify the Account's company property to be named differently (and modify the bootstrap accordingly), i.e.:

class Account extends Serializable {
    Company cmp
}

However, these are workarounds. I'm really interested in WHY this is happening. Anybody got a clue?

Just to be on the safe side, I did the following to create this problem:

  1. create domain class: my.classes.domain.Company
  2. create domain class: my.classes.domain.Account
  3. modify the domain class as above
  4. create a groovy class: my.clazz.Company
  5. give this groovy class the Validatable annotation.
  6. add the my.clazz package to the validateable packages
  7. in the bootstrap, create a new Account with new Account(company:company)


Aside from the various typos in your code which makes the problem hard to determine, the problem would seem to be that you are trying to set the Account.company property which is of type my.class.Company with the my.class.domain.Company type. Your bootstrap would need to be changed to:

import my.class.Company
import my.class.Account

Company company = new Company
Account acccount = new Account(company: company)

Note, the correct import statement for Company.


According to the error you describe, I think that Grails have determined wrong: the company you transfer into Account was determined as a my.clazz.Company, not my.classes.domain.Company.

You can put a simple check to know for sure what's the type of company in bootstrap:

import java.lang.Class;
...
println company.getClass().getName()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜