1 package com.thoughtworks.xstream.converters.basic; 2 3 import com.thoughtworks.xstream.converters.Converter; 4 import com.thoughtworks.xstream.converters.MarshallingContext; 5 import com.thoughtworks.xstream.converters.UnmarshallingContext; 6 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 7 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 8 9 18 public abstract class AbstractBasicConverter implements Converter { 19 20 protected abstract Object fromString(String str); 21 22 public abstract boolean canConvert(Class type); 23 24 protected String toString(Object obj) { 25 return obj.toString(); 26 } 27 28 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { 29 writer.setValue(toString(source)); 30 } 31 32 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 33 return fromString(reader.getValue()); 34 } 35 36 } 37 | Popular Tags |