XStream
  1. XStream
  2. XSTR-606

IterableConverter does not override marshal, causes ClassCastException when iterable is NOT a Collection

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.3.1
    • Fix Version/s: None
    • Component/s: Converters
    • Labels:
      None
    • JDK version and platform:
      java version "1.6.0_17" for mac

      Description

      From CollectionConverter (the super class)

          public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
              Collection collection = (Collection) source;
              for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
                  Object item = iterator.next();
                  writeItem(item, context, writer);
              }
          }
      

      the following code is commented out in IterableConverter

              @Override
              public void marshal( final Object                     value,
                                   final HierarchicalStreamWriter   writer,
                                   final MarshallingContext         context ) {
                  Iterable<?> it = (Iterable<?>) value;
      
                  writer.startNode( "list" );
                  for( Object o : it ) {
                      context.convertAnother( o );
                  }
                  writer.endNode();
              }
      ...
      

      i'm not sure why the code two bits of code look so different, but a decent fix would seemingly be to cast to an Iterable in CollectionConverter as this will always work, and would otherwise leave code unchanged.

        People

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

          Dates

          • Created:
            Updated:
            Resolved: