1 package com.thoughtworks.xstream.mapper; 2 3 import com.thoughtworks.xstream.alias.ClassMapper; 4 import com.thoughtworks.xstream.core.JVM; 5 6 12 public class EnumMapper extends MapperWrapper { 13 14 private static JVM jvm = new JVM(); 16 private static final Class enumClass = jvm.loadClass("java.lang.Enum"); 17 18 private static final boolean active = enumClass != null; 19 20 private static final Class enumSetClass = active ? jvm.loadClass("java.util.EnumSet") : null; 21 22 public EnumMapper(ClassMapper wrapped) { 23 super(wrapped); 24 } 25 26 public String serializedClass(Class type) { 27 if (!active) { 28 return super.serializedClass(type); 29 } else { 30 if (enumClass.isAssignableFrom(type) && type.getSuperclass() != enumClass) { 31 return super.serializedClass(type.getSuperclass()); 32 } else if (enumSetClass.isAssignableFrom(type)) { 33 return super.serializedClass(enumSetClass); 34 } else { 35 return super.serializedClass(type); 36 } 37 } 38 } 39 40 } 41 | Popular Tags |