XStream
  1. XStream
  2. XSTR-421

char cannot be serialized as attribute

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.3
    • Component/s: Converters
    • Labels:
      None
    • JDK version and platform:
      Sun Java 1.5.0_04

      Description

      I would like to serialize 'char' field as xml attribute. I used the following (pseudo)code:

      class A {
      char x;
      }
      XStream xstr = new XStream();
      xstr.useAttributeFor(A.class, "x");
      System.out.println(xstr.toXML(new A()));

      But no success. The workaround was to define my own Converter, with which it worked.
      I expected that such a thing should be defined by default.

      xstr.registerConverter(new SingleValueConverter(){
      public Object fromString(String arg0)

      { return arg0.charAt(0); }

      public String toString(Object arg0)

      { return String.valueOf(((Character)arg0)); }

      public boolean canConvert(Class arg0)

      { return (Character.class.isAssignableFrom(arg0)); }

      });

        People

        • Assignee:
          Unassigned
          Reporter:
          Jakub Neubauer
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: