XStream
  1. XStream
  2. XSTR-376

AttributeMapper problems with getDeclaredField() and inherieted fields

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.2
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      windows java 1.5

      Description

      AttributeMapper makes use of getDelcaredField() which has very onerous requirements of field visibility and inherited fields.

      Personally I find the whole approach taken by the AttributeMapper to be too heavy handed and would like to be able to easily specify that any type that can be handled by a SingleValueConverter should be written/read as an attribute.

      Up until the 1.2..2-SNAPSHOT the following approach worked well, I simply added the following MapperWrapper and

      class MyAttributeMapper extends MapperWrapper {

      XStream xStream;

      public MyAttributeMapper(Mapper wrapped, XStream xStream)

      { super(wrapped); this.xStream = xStream; }

      protected SingleValueConverter getLocalConverterFromItemType(Class type) {
      Converter converter = xStream.getConverterLookup().lookupConverterForType(type);
      if (converter != null && converter instanceof SingleValueConverter)

      { return (SingleValueConverter)converter; }

      else

      { return null; }

      }

      public SingleValueConverter getConverterFromItemType(Class type)

      { return getLocalConverterFromItemType(type); }

      }

      However testing with 1.2.2-SNAPSHOT our entire application bombs because of the added restriction introduced by the use of getDeclaredField() in AttributeMapper, as an example, see the following test :

      1. Test.java
        0.7 kB
        J. Matthew Pryor

        People

        • Assignee:
          Unassigned
          Reporter:
          J. Matthew Pryor
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: