Package de.timroes.axmlrpc.serializer

Source Code of de.timroes.axmlrpc.serializer.DoubleSerializer

package de.timroes.axmlrpc.serializer;

import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLUtil;
import de.timroes.axmlrpc.xmlcreator.XmlElement;
import java.math.BigDecimal;
import org.w3c.dom.Element;

/**
* This serializer is responsible for floating point numbers.
*
* @author Tim Roes
*/
public class DoubleSerializer implements Serializer {

  public Object deserialize(Element content) throws XMLRPCException {
    return Double.valueOf(XMLUtil.getOnlyTextContent(content.getChildNodes()));
  }

  public XmlElement serialize(Object object) {
    // Turn double value of object into a BigDecimal to get the
    // right decimal point format.
    BigDecimal bd = BigDecimal.valueOf(((Number)object).doubleValue());
    return XMLUtil.makeXmlTag(SerializerHandler.TYPE_DOUBLE, bd.toPlainString());
  }

}
TOP

Related Classes of de.timroes.axmlrpc.serializer.DoubleSerializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.