redstone.xmlrpc
Class XmlRpcJsonSerializer

java.lang.Object
  extended by redstone.xmlrpc.XmlRpcSerializer
      extended by redstone.xmlrpc.XmlRpcJsonSerializer

public class XmlRpcJsonSerializer
extends XmlRpcSerializer

The XmlRpcJsonSerializer class converts Java objects to their JSON counterparts. It inherently supports basic object types like String, Integer, Double, Float, Boolean, Date, and byte arrays. For other types of objects, custom serializers need to be registered. The Redstone XML-RPC library comes with a set of useful serializers for collections and other types of objects. @see the redstone.xmlrpc.serializers.json . Although this is not what you would expect to find in an XML-RPC library, implementing a JSON serializer required very little effort and gives great value for JavaScript clients that wants to use XML-RPC services in their AJAX implementations. It is easy to create XML-RPC compatible messages in JavaScript but less easy to parse the response which is not required using this format, just use eval( responseText ) to get a JavaScript object. TODO Change synchronization of global dateFormatter to prevent bottleneck.

Author:
Greger Olsson

Constructor Summary
XmlRpcJsonSerializer()
          Constructor adding all core custom serializers.
XmlRpcJsonSerializer(boolean addCustomSerializers)
          Constructor that may add all the custom serializers in the library (which is almost always what you want).
 
Method Summary
 void serialize(java.lang.Object value, java.io.Writer writer)
          Overrides the default serializing mechanism to use JSON format instead.
 void writeEnvelopeFooter(java.lang.Object value, java.io.Writer writer)
          Overrides the default serializing mechanism to use JSON format instead.
 void writeEnvelopeHeader(java.lang.Object value, java.io.Writer writer)
          Overrides the default serializing mechanism to use JSON format instead.
 void writeError(java.lang.String message, java.io.Writer writer)
          Overrides the default serializing mechanism to use JSON format instead.
 
Methods inherited from class redstone.xmlrpc.XmlRpcSerializer
addCustomSerializer, removeCustomSerializer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlRpcJsonSerializer

public XmlRpcJsonSerializer()
Constructor adding all core custom serializers.


XmlRpcJsonSerializer

public XmlRpcJsonSerializer(boolean addCustomSerializers)
Constructor that may add all the custom serializers in the library (which is almost always what you want).

Parameters:
addCustomSerializers - Indicates if the core custom serializers should be added.
Method Detail

writeEnvelopeHeader

public void writeEnvelopeHeader(java.lang.Object value,
                                java.io.Writer writer)
                         throws java.io.IOException
Overrides the default serializing mechanism to use JSON format instead.

Overrides:
writeEnvelopeHeader in class XmlRpcSerializer
Throws:
java.io.IOException

writeEnvelopeFooter

public void writeEnvelopeFooter(java.lang.Object value,
                                java.io.Writer writer)
                         throws java.io.IOException
Overrides the default serializing mechanism to use JSON format instead.

Overrides:
writeEnvelopeFooter in class XmlRpcSerializer
Throws:
java.io.IOException

writeError

public void writeError(java.lang.String message,
                       java.io.Writer writer)
                throws java.io.IOException
Overrides the default serializing mechanism to use JSON format instead.

Overrides:
writeError in class XmlRpcSerializer
Throws:
java.io.IOException

serialize

public void serialize(java.lang.Object value,
                      java.io.Writer writer)
               throws XmlRpcException,
                      java.io.IOException
Overrides the default serializing mechanism to use JSON format instead.

Overrides:
serialize in class XmlRpcSerializer
Throws:
XmlRpcException
java.io.IOException