1 package com.thoughtworks.xstream.converters.collections; 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 15 public class CharArrayConverter implements Converter { 16 17 public boolean canConvert(Class type) { 18 return type.isArray() && type.getComponentType().equals(char.class); 19 } 20 21 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { 22 char[] chars = (char[]) source; 23 writer.setValue(new String (chars)); 24 } 25 26 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 27 return reader.getValue().toCharArray(); 28 } 29 } 30 | Popular Tags |