XStream
  1. XStream
  2. XSTR-415

Let JavaBeanConverter use bean introspection

    Details

    • Type: Wish Wish
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: Converters
    • Labels:
      None

      Description

      Currently the JavaBeanConverter uses reflection. Maybe it's better to use bean introspection. The attached patch changes BeanProvider, so that it uses bean introspection.

      Maybe it's better to add a setBeanProvider info to the JavaBeanConverter in order to support other (custom) BeanProviders.

      1. BeanWithBeanInfoConverter.java
        15 kB
        Jim Redman
      2. patch.txt
        6 kB
        Hinse ter Schuur

        Issue Links

          Activity

          Hide
          Jim Redman added a comment -

          Here's an alternate approach in case you are interested. We save the types, because, for example, byte or char types will not be handle correctly if the type is not encoded in the file. It also only writes changed properties and uses the current class loader to get the beaninfo (should probably default to Introspection if the beaninfo does not exist, etc. etc. etc.).

          There are some other tweaks, like not saving a property if it is hidden and expert, not saving read-only properties, etc. Also has mapping of class names, so that if you move a bean from one package to another, or just rename it, you can still read the file (I think that this duplicates a feature that is already in XStream).

          We've been using this for close to 2 years now. It saves and restores our 200+ javabeans (http://www.ergotech.com) and most of the javabean editor. That is, we treat our screens and similar as a JavaBeans.

          Show
          Jim Redman added a comment - Here's an alternate approach in case you are interested. We save the types, because, for example, byte or char types will not be handle correctly if the type is not encoded in the file. It also only writes changed properties and uses the current class loader to get the beaninfo (should probably default to Introspection if the beaninfo does not exist, etc. etc. etc.). There are some other tweaks, like not saving a property if it is hidden and expert, not saving read-only properties, etc. Also has mapping of class names, so that if you move a bean from one package to another, or just rename it, you can still read the file (I think that this duplicates a feature that is already in XStream). We've been using this for close to 2 years now. It saves and restores our 200+ javabeans ( http://www.ergotech.com ) and most of the javabean editor. That is, we treat our screens and similar as a JavaBeans.
          Hide
          Hinse ter Schuur added a comment -

          Added an updated version of the JavaBeanConverter and BeanProvider as attachement of issue <a href="http://jira.codehaus.org/browse/XSTR-280">XSTR-280</a>. Contains fix for omitted fields and field aliases.

          Show
          Hinse ter Schuur added a comment - Added an updated version of the JavaBeanConverter and BeanProvider as attachement of issue <a href="http://jira.codehaus.org/browse/XSTR-280"> XSTR-280 </a>. Contains fix for omitted fields and field aliases.
          Hide
          Jörg Schaible added a comment -

          @Hinse:
          Thanks for your patch. I've added a modified version of the patch you've provided in XSTR-280 and made the tests JDK independent.

          @Jim:
          Also thank you for your contribution. Basically the functionality is already too specialized, some of it can already be done with other mechanisms of XStream. However, there are some interesting details.

          Show
          Jörg Schaible added a comment - @Hinse: Thanks for your patch. I've added a modified version of the patch you've provided in XSTR-280 and made the tests JDK independent. @Jim: Also thank you for your contribution. Basically the functionality is already too specialized, some of it can already be done with other mechanisms of XStream. However, there are some interesting details.
          Hide
          Jörg Schaible added a comment -

          Closing issues before next release.

          Show
          Jörg Schaible added a comment - Closing issues before next release.

            People

            • Assignee:
              Jörg Schaible
              Reporter:
              Hinse ter Schuur
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: