package org.codehaus.xfire.aegis.type.basic; import org.codehaus.xfire.MessageContext; import org.codehaus.xfire.aegis.MessageReader; import org.codehaus.xfire.aegis.MessageWriter; import org.codehaus.xfire.aegis.type.Type; /** * SimpleSerializer * * @author Dan Diephouse */ public class LongType extends Type { public Object readObject(MessageReader reader, MessageContext context) { return new Long( reader.getValueAsLong() ); } public void writeObject(Object object, MessageWriter writer, MessageContext context) { /** *

* This conditional is to check if a object is really a Long. If it isn't * assume that it is a Number and cast it to a Number * and create a new Long with that value. *

* *

* This should only ever happen if a property in a object is an interface * or base class and java refection does create the object with the correct type. *

*/ if(object instanceof Long){ writer.writeValueAsLong( (Long) object ); } else{ writer.writeValueAsLong( new Long(((Number)object).longValue()) ); } } }