Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Upcoming
    • Fix Version/s: Upcoming
    • Component/s: Converters, Core
    • Labels:
      None
    • JDK version and platform:
      Sun 1.6.0_03-b05 on Linux

      Description

      The submitted patch enables XStream to handle XML with unknown nodes, i.e. nodes that were not mapped to fields within my classes.

      The features of this patch are:
      1. Any XML can be unmarshaled to classes - unknown nodes/attributes (ones that do not map to fields in classes) will not produce any error.
      2. Such unknown nodes will be internally stored (some restrictions apply).
      3. When marshaling objects tree back to XML, stored unknown nodes will be also written. This will produce XML where unknown parts will not be touched.

      How this patch works:
      1. In case of unknown nodes DefaultMapper (which is the last in line of mappers) throws an CannotResolveClassException. Patch changes this so that DefaultMapper instead returns UnknownNode class.
      2. Since UnknownNode class does not have it's own converter, it will be ultimately handled by AbstractReflectionConverter. ARC's methods doMarshal/doUnmarshal are changed so that when unknown nodes are detected they get saved to node storage.
      3. For handling unknown nodes inside lists, CollectionConverter and AbstractCollectionConverter are enhanced.
      4. New classes NodeStorage and NodeTree implement a mechanism for storing/retrieving trees of nodes and attributes. NodeStorage remembers (via weak references) which unmarshaled objects had unknown attributes/subnodes and saves references in an internal map.
      5. Custom facade XStreamCaching binds above mentioned classes together. XSC holds a reference to NodeStorage instance, and passes it via custom constructors to those classes.

      Current limitations:
      A. NodeStorage uses object references to remember which unknown saved nodes belong to which (unmarshaled) objects. Restoring unknown nodes only works for objects that were created via unmarshaling (fromXML()). If objects are created from scratch or existing objects are changed in a way that changes their references (copied?), marshaling unknown nodes will do nothing (it will behave as plain XStream). This could be handled by by some kind of unknownAlias(Object original Object changed) method that would add a new reference to the map. Any thoughts?
      B. At the moment only collections handled by CollectionConverter (ArrayList, LinkedList, HashSet, Vector, LinkedHashSet) are suported. Support for other collections (array, Map, TreeMap, etc..) will be added in a week or so.
      C. Unknown nodes (and attributes) are only detected when they are inside users classes (or if their parent is also unknown node) handled via AbstractCollectionConverter. If there is a node that is handled by any of the built in converters, for example StringConverter, the unknown subnodes and attributes will not be detected. Handling this cases would require changing all existing converters in XStream. Can anybody think of a way that this could be handled in a more general way?

        Issue Links

          Activity

          Hide
          Peter Knego added a comment - - edited

          This patch was made against trunk about 20 months ago. I don't think that it can be applied now. Some people have tried but Xstream internals have changed, so it doesn't work any more.

          Anyhow, this patch was not accepted in Xstream. Also I realized that Xstream was not meant to be used in this way - mapping external XML and preserving unmapped nodes. Xstream is a library for object serialization, not a XML mapping library.

          So I started a new XML mapper project that can do this: http://xmappr.googlecode.com

          Regards, Peter

          Show
          Peter Knego added a comment - - edited This patch was made against trunk about 20 months ago. I don't think that it can be applied now. Some people have tried but Xstream internals have changed, so it doesn't work any more. Anyhow, this patch was not accepted in Xstream. Also I realized that Xstream was not meant to be used in this way - mapping external XML and preserving unmapped nodes. Xstream is a library for object serialization, not a XML mapping library. So I started a new XML mapper project that can do this: http://xmappr.googlecode.com Regards, Peter
          Hide
          Jörg Schaible added a comment -

          Anyhow, this patch was not accepted in Xstream.

          No, in that case this issue would have been closed. However, it adds functionality to XStream that has to be carefully considered and supported in more places than the ones in the patch (no pun intended, nobody can expect that someone providing a patch knows all internals and cases). The approach is nevertheless interesting, therefore - thanks for the contribution. There had been simply more urgent issues within a limited time frame

          Show
          Jörg Schaible added a comment - Anyhow, this patch was not accepted in Xstream. No, in that case this issue would have been closed. However, it adds functionality to XStream that has to be carefully considered and supported in more places than the ones in the patch (no pun intended, nobody can expect that someone providing a patch knows all internals and cases). The approach is nevertheless interesting, therefore - thanks for the contribution. There had been simply more urgent issues within a limited time frame
          Hide
          pradeep added a comment -

          Hi, is there any update in this feature???
          or any new solution for handling new tags which are not having respective attribute in the java bean?

          Show
          pradeep added a comment - Hi, is there any update in this feature??? or any new solution for handling new tags which are not having respective attribute in the java bean?
          Hide
          vijay added a comment -

          Any udpates on this. I see that the patch was not accepted but what is the workaround for this? I am in dire need of a solution for this.

          Show
          vijay added a comment - Any udpates on this. I see that the patch was not accepted but what is the workaround for this? I am in dire need of a solution for this.
          Hide
          Jörg Schaible added a comment -

          This is a bug tracker and not a help forum. If you have questions, use the list.

          I see that the patch was not accepted

          And stop to spread FUD.

          Show
          Jörg Schaible added a comment - This is a bug tracker and not a help forum. If you have questions, use the list. I see that the patch was not accepted And stop to spread FUD.

            People

            • Assignee:
              Unassigned
              Reporter:
              Peter Knego
            • Votes:
              5 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: