XStream
  1. XStream
  2. XSTR-406

Provide reflection & annotation data to converter code

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.4.2
    • Component/s: Converters, Core
    • Labels:
      None

      Description

      While trying to implement a workaround to accomplish XSTR-405, I found no way for the code in a marshal method to access the annotations associated with the field/value that is being converted.

      If this were possible, then it would be easy for developers to attach their own annotations and read them from the code that would convert a given class, without having to provide their own top-level converter.

      It may seem like @XStreamConverter is an out here, but it offers no mechanism for providing per-use data values – and I don't think it could.

      That is, you could not have (and would not want):

      @XStreamConverter(class=MyClassConverter.class, customTweak=true)
      MyClass fieldA;

      @XStreamConverter(class=MyClassConverter.class, customTweak=false, tagName="foo")
      MyClass fieldB;

      But, if annotations were passed along, perhaps as part of the MarshallingContext, then I could write:

      @XStreamConverter(MyClassConverter.class)
      @MyAnno(customTweak=true)
      MyClass fieldA;

      @XStreamConverter(MyClassConverter.class)
      @MyAnno(customTweak=true, tagName="foo")
      MyClass fieldB;

      It would also be very useful in the canConvert class to get access to this data. For compatibility, you could perhaps have:

      interface ReflectiveConverter {
      canConvert(Class clazz, AccessibleObject aobject);
      }

      and call that instead if the converter implements it.

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          John Redford
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: