Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-228

[beanutils] ConvertUtilsBean: register converter for specific property

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.5
    • Fix Version/s: 2.0
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      Currently, converters are selected only based on the class to which they
      convert objects. In general this works pretty well, but I've encountered
      cases, where this doesn't work out.

      For example, I'm using java.util.Date objects to represent points and
      intervals in time that are not completely specific, such as day of the week
      and month. Now I can easily write a Converter that uses SimpleDateFormat to
      convert string representations of these dates ("Mon", "Feb") to Date objects.

      When I register one of these converters with ConvertUtils(Bean), though, it
      preempts any conversion to Date. Something I clearly don't want as I have to
      deal with different kinds of dates.

      As a solution, I'd like to be able to register a converter for a specific
      property of a bean class, with a method this

      ConvertUtilsBean#register(Converter converter, java.lang.Class
      destinationClass, java.lang.Class beanClass, java.lang.String propertyName)

      Michael

        Issue Links

          Activity

          Michael Schuerig created issue -
          Henri Yandell made changes -
          Field Original Value New Value
          issue.field.bugzillaimportkey 31568 12341784
          Henri Yandell made changes -
          Key COM-1632 BEANUTILS-228
          Affects Version/s 1.5 Final [ 12311664 ]
          Project Commons [ 12310458 ] Commons BeanUtils [ 12310460 ]
          Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
          Component/s BeanUtils [ 12311101 ]
          Henri Yandell made changes -
          Affects Version/s 1.5 Final [ 12311720 ]
          Niall Pemberton made changes -
          Link This issue is duplicated by BEANUTILS-253 [ BEANUTILS-253 ]
          Niall Pemberton made changes -
          Bugzilla Id 31568
          Component/s Converters [ 12311455 ]
          Henri Yandell made changes -
          Fix Version/s 1.8.0 [ 12311949 ]
          Bugzilla Id 31568
          Hide
          Henri Yandell added a comment -

          I wonder if the destinationClass is necessary in this API. It seems that the user will get all they need with:

          register(Converter, Class beanClass, String propertyName).

          Thoughts?

          Show
          Henri Yandell added a comment - I wonder if the destinationClass is necessary in this API. It seems that the user will get all they need with: register(Converter, Class beanClass, String propertyName). Thoughts?
          Niall Pemberton made changes -
          Fix Version/s LATER THAN 1.8.0 [ 12312151 ]
          Fix Version/s 1.8.0 [ 12311949 ]
          Hide
          Adam Hardy added a comment - - edited

          I agree with Henri that naming the destination class and the bean.property is overkill for that situation. Leaving the original method signature as it is would be well complemented by a method signature following Michael's suggestion but with just the bean and property params.

          That raises the question of which converter would have precedence if both were registered - obviously the more specific one would be preferable but I can imagine the algorithm to implement that would not be facile.

          Also, I think it would be a great thing to enhance the converter.convert method signature to pass in the owning class's setter or getter method or field, from which it's possible to deduce the parameterized type for lists, sets, maps etc.

          This would help when trying to construct a list of a specific bean for instance.

          List<MyParticularBean> getMyParticularBeans()

          This type info is erased at compilation from the List class itself - it is only the methods or field which still hold the info. I can put this in a seperate issue if necessary.

          Show
          Adam Hardy added a comment - - edited I agree with Henri that naming the destination class and the bean.property is overkill for that situation. Leaving the original method signature as it is would be well complemented by a method signature following Michael's suggestion but with just the bean and property params. That raises the question of which converter would have precedence if both were registered - obviously the more specific one would be preferable but I can imagine the algorithm to implement that would not be facile. Also, I think it would be a great thing to enhance the converter.convert method signature to pass in the owning class's setter or getter method or field, from which it's possible to deduce the parameterized type for lists, sets, maps etc. This would help when trying to construct a list of a specific bean for instance. List<MyParticularBean> getMyParticularBeans() This type info is erased at compilation from the List class itself - it is only the methods or field which still hold the info. I can put this in a seperate issue if necessary.
          Oliver Heger made changes -
          Fix Version/s 2.0 [ 12325663 ]
          Fix Version/s LATER THAN 1.8.4 [ 12312151 ]

          Error rendering 'com.atlassian.jirafisheyeplugin:fisheye-issuepanel'. Please contact your JIRA administrators.

            People

            • Assignee:
              Unassigned
              Reporter:
              Michael Schuerig
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development