XStream
  1. XStream
  2. XSTR-148

Exception when unmarshalling an "Interface"

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.2
    • Component/s: None
    • Labels:
      None

      Description

      An exception (java.lang.InstantiationError) is raised when unmarshalling an "Interface". Attached is a testcase below as well as the fix. The fix is a one liner in the convertAnother() in TreeUnmarshaller.java (below).

      I apologize for not know how to generate a patch. I would appreciate if someone can tell me how do to it in eclipse.

      Thanks in advance

      chung-onn

      TreeUnmarshaller.java
      =====================

      public Object convertAnother(Object parent, Class type) {
      try

      { Converter converter = converterLookup.lookupConverterForType(type); //types.push(type); //the "bug" types.push(classMapper.lookupDefaultType(type)); //the fix Object result = converter.unmarshal(reader, this); types.popSilently(); return result; }

      catch (ConversionException conversionException)

      { addInformationTo(conversionException, type); throw conversionException; }

      catch (RuntimeException e)

      { ConversionException conversionException = new ConversionException(e); addInformationTo(conversionException, type); throw conversionException; }

      }

      Testcase
      =======

      import java.util.ArrayList;
      import java.util.List;
      import junit.framework.TestCase;

      import com.thoughtworks.xstream.XStream;

      public class XStreamTester extends TestCase {
      public static void main(String[] args)

      { junit.textui.TestRunner.run(XStreamTester.class); }

      /*

      • Test alias for interface class
        */
        public void testAlias() { System.out.println("\nAlias with aliased xmlString"); XStream xs = new XStream(); xs.alias("addressBookInfo",AddressBookInfo.class,AddressBook.class); xs.alias("addressInfo",AddressInfo.class, Address.class); AddressBookInfo addrInfo = new AddressBook(); String xmlString = xs.toXML(addrInfo); System.out.println("***xmlstring:\n" +xmlString); AddressBookInfo addrInfo1 = (AddressBookInfo) xs.fromXML(xmlString); System.out.println(" Object:"+addrInfo1); System.out.println("***xmlString:\n"+xs.toXML(addrInfo1)); }

      /*

      • Test aliasing after from a non-alias xmlstring
        */
        public void testAlias1() { System.out.println("\nAlias without aliased xmlString"); XStream xs = new XStream(); AddressBookInfo addrInfo = new AddressBook(); String xmlString = xs.toXML(addrInfo); System.out.println("***xmlstring:\n" +xmlString); xs.alias("addressBookInfo",AddressBookInfo.class,AddressBook.class); xs.alias("addressInfo",AddressInfo.class, Address.class); AddressBookInfo addrInfo1 = (AddressBookInfo) xs.fromXML(xmlString); System.out.println(" Object:"+addrInfo1); System.out.println("***xmlString:\n"+xs.toXML(addrInfo1)); }

      public interface AddressBookInfo

      { public List getAddresses(); public void setAddresses(List address); }

      public class AddressBook implements AddressBookInfo {
      private List addresses;

      public AddressBook()

      { addresses = new ArrayList(); AddressInfo addr = new Address("Home","Home"); AddressInfo addr1 = new Address("Office","Office"); addresses.add(addr); addresses.add(addr1); }

      public List getAddresses()

      { return addresses; }

      public void setAddresses(List addresses)

      { this.addresses = addresses; }

      }

      public interface AddressInfo

      { public String getAddr1(); public String getAddr2(); public void setAddr1(String addr1); public void setAddr2(String addr2); }

      public class Address implements AddressInfo {
      private String addr1="addr1";
      private String addr2="addr2";

      public Address(String addr1, String addr2)

      { this.addr1 = addr1; this.addr2 = addr2; }

      public String getAddr1()

      { return addr1; }

      public String getAddr2()

      { return addr2; }

      public void setAddr1(String addr1)

      { this.addr1 = addr1; }

      public void setAddr2(String addr2)

      { this.addr2 = addr2; }

      }

      }

        People

        • Assignee:
          Unassigned
          Reporter:
          Cheong, Chung-Onn
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: