XStream
  1. XStream
  2. XSTR-570

@XStreamConverter should allow target type information in Constructor

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4
    • Component/s: Annotations
    • Labels:
      None
    • JDK version and platform:
      Sun 1.5_11 under windows

      Description

      @XStreamConverter currently only supports Converters which take none or a small set of arguments using DependencyInjectionFactory (AnnotationMapper, ClassLoader, ReflectionProvider, and/or JVM), but not the target type. It's fairly common that a Converter would want to know what type of value to which it's trying to convert. This is especially true for SingleValueConverters which do not have any way to get this information (full Converters can get it from the UnmarshallingContext, but then can't be used as attributes).

      I've included a replacement AnnotationMapper and test case.

      The changes to AnnotationMapper are fairly minor:

      • Modified the cacheConverter method to take the target Class argument
      • Added the target Class to the arguments when calling DependencyInjectionFactory.newInstance(...).
      • Modified the internal cache to make sure that it caches both the converterType and the target class with the Converter instance rather than just the converterType with the Converter instance. This makes the caching less efficient, but makes sure that a ToStringConverter instance for Doubles doesn't try to convert a Boolean.

      The test class included makes use of the ToStringConverter which is included with the standard distribution.

      1. AnnotationMapper.java
        22 kB
        Jason Greanya
      2. ConverterWithTypeTest.java
        2 kB
        Jason Greanya

        People

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

          Dates

          • Created:
            Updated:
            Resolved: