How to use CustomSerializers wiht XmlRpcProxy

Help
tomgus
2008-11-06
2013-04-25
  • tomgus
    tomgus
    2008-11-06

    Hi

    i try to register custom Serializers like in marquee

    Can someone give me an example how to do this?

    XmlRpcSerializer.addCustomSerializer(new VectorSerializer());

    results in:
    Cannot make a static reference to the non-static method addCustomSerializer(XmlRpcCustomSerializer) from the type XmlRpcSerializer

    the VectorSerializers is implementation of XmlRpcCustomSerializer

    bye
    Thomas

     
    • Greger Ohlson
      Greger Ohlson
      2008-11-06

      Hi Thomas!

      Each XmlRpcServer has its own instance of XmlRpcSerializer. So in order to add extra serializers to a particulat XmlRpcServer you need to get its serializer instance first:

      xmlRpcServer.getSerializer().addCustomSerializer(new VectorSerializer());

      Note though, that the built-in serializer can already serialize vectors since it includes a custom collection serializer, and Vector is an implementation of Collection.

      The following custom serializers are added by default:

      redstone.xmlrpc.serializers.MapSerializer
      redstone.xmlrpc.serializers.ListSerializer
      redstone.xmlrpc.serializers.CollectionSerializer  <-- this handles Vector too
      redstone.xmlrpc.serializers.ObjectArraySerializer
      redstone.xmlrpc.serializers.IntArraySerializer
      redstone.xmlrpc.serializers.FloatArraySerializer
      redstone.xmlrpc.serializers.DoubleArraySerializer
      redstone.xmlrpc.serializers.BooleanArraySerializer
      redstone.xmlrpc.serializers.IntrospectingSerializer

      Hope this helps.

      Regards,
      Greger.

       
    • Greger Ohlson
      Greger Ohlson
      2008-11-06

      Hi again,

      A slight correction, java.util.Vector also implements the java.util.List interface, in addition to the Collection interface. So it is in fact the redstone.xmlrpc.serializers.ListSerializer that will serialize any Vector objects you have in your requests or responses, since the ListSerializer is included before the CollectionSerializer in the built-in list of custom serializers.

      The result is the same though, any Vector parameters you have in your server, or send through an XmlRpcClient will be serialized without you having to include your own VectorSerializer.

      Cheers,
      Greger.

       
  • Rane Bowen
    Rane Bowen
    2012-08-07

    Would be good to be able to add custom serializers on the XmlRpcClient/XmlRpcProxy, but from looking at the source code, this does not seem possible.