Example #1
0
    /**
     * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
     *     com.thoughtworks.xstream.io.HierarchicalStreamWriter,
     *     com.thoughtworks.xstream.converters.MarshallingContext)
     */
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      Quota quota = (Quota) source;
      BigInteger bytes = quota.getBytes();
      StorageUnit unit = StorageUnit.bestFit(bytes);
      BigDecimal value = unit.fromBytes(bytes);

      writer.startNode("value");
      writer.setValue(value.toString());
      writer.endNode();

      writer.startNode("units");
      writer.setValue(unit.toString());
      writer.endNode();
    }