Menu

#12 Java Bean fields of a supertype of the object to be set

2.0.0-beta-1
closed
None
5
2012-09-16
2010-01-03
No

SuperCSV does not support setting Java Bean fields that are not the exact type of the object that the outermost cell processor returns. In most cases this is merely an inconvenience and one may create a custom cell processor that returns an object of the correct type, but this is not an option for fields of an abstract/interface type.

Enclosing my suggestion for a fix. This modifies org.supercsv.util.MethodCache to replace Class.getMethod(...) with a new method getAnyAssignableMethod(...) that searches for any mutator that can take the type being set as an argument, but which will give preference to mutators whose type matches exactly.

Discussion

  • Thor Michael Støre

    Support for Java Bean field supertypes

     
  • Thor Michael Støre

    org.supercsv.mock.SuperTypeFieldBean for tests

     
  • Thor Michael Støre

    Attaching SuperTypeFieldBean, which I forgot. It's just a PersonBean but with CharSequence instead of Strings as field types.

     
  • Kasper B. Graversen

    Hi Thor

    Sounds like an idea. I've looked at your code and it looks straight forward. I'm planning a releasing something within a month and will probably include your patch :)

    cheers,
    kasper

     
  • James Bassett

    James Bassett - 2012-07-06

    Thanks for the patch - I've just added this for the next release - see ReflectionUtils.findSetterWithCompatibleParamType().
    For your effort, I've added you as a contributor in the pom :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.