"custom converter in xstream" Code Answer

6

here is the converter you need:

public class detaildollarsconverter extends reflectionconverter {

public detaildollarsconverter(mapper mapper,
        reflectionprovider reflectionprovider) {
    super(mapper, reflectionprovider);
}

@override
public void marshal(object obj, hierarchicalstreamwriter writer,
        marshallingcontext context) {
    super.marshal(obj,writer,context);

    detaildollars dl = (detaildollars) obj;

    writer.startnode("node4");
    writer.setvalue(double.tostring(dl.getnode1() / dl.getnode2()));
    writer.endnode();
}

@override
public object unmarshal(hierarchicalstreamreader reader,
        unmarshallingcontext context) {
    return super.unmarshal(reader,context);
}

@suppresswarnings("unchecked")
@override
public boolean canconvert(class clazz) {
    return clazz.equals(detaildollars.class);
}

}

By AbraCadaver on June 7 2022

Answers related to “custom converter in xstream”

Only authorized users can answer the Search term. Please sign in first, or register a free account.