net.sf.juffrou.xml.serializer.EnumSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of juffrou-xml Show documentation
Show all versions of juffrou-xml Show documentation
Juffrou XML is simplified marshaling for java beans into XML and back.
package net.sf.juffrou.xml.serializer;
import net.sf.juffrou.reflect.JuffrouBeanWrapper;
import net.sf.juffrou.xml.internal.io.JuffrouReader;
import net.sf.juffrou.xml.internal.io.JuffrouWriter;
public class EnumSerializer implements Serializer {
@Override
public void serialize(JuffrouWriter writer, JuffrouBeanWrapper valueOwner, String valuePropertyName) {
writer.write(valueOwner.getValue(valuePropertyName).toString());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void deserialize(JuffrouReader reader, JuffrouBeanWrapper valueOwner, String valuePropertyName) {
String value = reader.getText();
Class clazz = valueOwner.getClazz(valuePropertyName);
valueOwner.setValue(valuePropertyName, Enum.valueOf(clazz, value));
}
}