XStream
  1. XStream
  2. XSTR-688

When unmarshal XML, xSream pass incorrect "definedIn" in Mapper.shouldSerializeMember

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 1.4.3
    • Component/s: Converters
    • Labels:
      None
    • JDK version and platform:
      Sun 1.6.0_27-b07 Windows 7

      Description

      When unmarshaling an XML the XStream verify if the field must be deserialized using Mapper.shouldSerializeMember(java.lang.Class definedIn, java.lang.String fieldName)

      The verification done by com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context)
      The problem is that the class passed in shouldSerializeMember as "definedIn" parameter is incorrect.

      Example:

      class A{String a;}
      class B extends A{String b;}
      

      when unmarshaling the instance of the class B and verifying field "String a" , xStream pass into shouldSerializeMember the class B as "definedIn" instead of class A.

      —
      The problem is in the class com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter at line 302.
      I suggest to you to change this line:

      "|| !mapper.shouldSerializeMember(classDefiningField != null ? classDefiningField : result.getClass(), fieldName)) {"

      by

      "|| !mapper.shouldSerializeMember(field.getDeclaringClass(), fieldName)) {"

      Failing unit test:

        People

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

          Dates

          • Created:
            Updated:
            Resolved: