ruby / ruby/xmlrpc

Easier way to serialize objects over XMLRPC

Open
#15 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
41
Forks
25
PR merge metrics
No merged PRs in 30d

Description

Currently there is no simple way to transport a non-default object over XMLRPC with this lib.

Contrived example

We have a Money class, with 3 values: currency (like Dollar, Euro, Yen), whole and cents. With Money.new(:dollar, 13, 37) we'd create a new object to represent $ 13.37.

Current ways to transfer this over XMLRPC:

Convert it to a more basic structure

We could convert this object manually to the String "$ 13.37" and transfer this. This means manual intervention on every XMLRPC call.

Use XMLRPC::Marshallable

This would result in marshalled objects that look pretty specific to Ruby, which would stop interoperability with other languages. This same problem arises when using Marshall or YAML to dump the structure.

Use Structs

There is logic to write structs over XMLRPC, but this loses the class name. If we had an abstract Money class that didn't save the currency, but instead had a Dollar, Euro and Yen subclass (like I said: contrived example), everything would be marshalled as the value only, without the currency. It basicly converts a Struct to a Hash

Override XMLRPC::Create#wrong_type

We could include duck typing here, but that feels cumbersome

Proposed solutions

I think there are two possible options to improve this:

Duck typing on to_xmlrpc

Allow classes to implement a #to_xmlrpc method, call that if applicable and use that converted value. This is comparable with things like #to_json. A point of discussion here is we'd have to have the method create an XMLRPC element, or if it just enough to create a String, Integer, Hash or whatever and feed that back into conv2value

Register classes in XMLRPC::Create

A different solution would be to register a class and conversion block in XMLRPC::Create, syntax would be a bit like this:

XMLRPC::Create.register_serializer(Money) { |obj| "MONEY: #{obj}" }

Where the exact value would depend upon agreements between client and server

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing XMLRPC::Create#wrong_type and conv2value, then compare the proposed #to_xmlrpc and register_serializer approaches. No file or test is named in the issue; done requires an agreed serialization API that preserves interoperability and coverage for custom objects such as Money.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.