Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After writing attribute converter. Problem is solved.</p> <pre><code>package com.xstream; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; public class Attribute { @XStreamAsAttribute private String name; private String value; public Attribute(String name, String value) { this.name = name; this.value = value; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the value */ public String getValue() { return value; } /** * @param value the value to set */ public void setValue(String value) { this.value = value; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Attribute [name=" + name + ", value=" + value + "]"; } } </code></pre> <p><code>AttributeConverter</code> class is:</p> <pre><code>package com.xstream; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; public class AttributeConverter implements Converter{ @Override public boolean canConvert(Class clazz) { return clazz.equals(Attribute.class); } @Override public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) { System.out.println("object = " + object.toString()); Attribute attribute = (Attribute) object; writer.addAttribute("name", attribute.getName()); writer.setValue(attribute.getValue()); } @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return new Attribute(reader.getAttribute("name"), reader.getValue()); } } </code></pre> <p>Use this in Qualification class as:</p> <pre><code> @XStreamConverter(AttributeConverter.class) private Attribute attribute; </code></pre> <p>Register converter in main class as:</p> <pre><code>xstream.registerConverter(new AttributeConverter()); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload