Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Egregious hack to add date and base64 types to JSON for XML-RPC
{
"methodCall": {
"methodName": "examples.echoParams",
"params": [
"#dateTime=2018-06-10T19:41:06.199Z",
"#base64=aGVsbG8gd29ybGQ="
]
}
}
{
"methodCall": {
"methodName": "examples.echoParams",
"params": [
{
"#type": "dateTime",
"#value": "2018-06-10T19:41:06.199Z"
},
{
"#type": "base64",
"#value": "aGVsbG8gd29ybGQ="
}
]
}
}
@scripting

This comment has been minimized.

Show comment
Hide comment
@scripting

scripting Jun 10, 2018

BTW, here's the post that explains why I'm interested in this --

http://scripting.com/2018/06/10/152333.html

Dave

Owner

scripting commented Jun 10, 2018

BTW, here's the post that explains why I'm interested in this --

http://scripting.com/2018/06/10/152333.html

Dave

@richardtallent

This comment has been minimized.

Show comment
Hide comment
@richardtallent

richardtallent Jun 10, 2018

Don’t make consumers look inside the value to determine the type. Pass an object with explicit type and value keys. Or even an object with a single key, the type, ie:

params: [
{ serialized: true, dateTime: “...” }
{ serialized: true, base64: “...” },
// probably better to do this:
{ serialized: true, encoding: “iso8601”, value: “2018...” },
{ serialized: true, encoding: “base64”, value: “...” }
]

Typing on my phone, apologies for formatting. Basically pass an object that the consumer can quickly identify as a serialized string so it can pass it to the appropriate code to deserialize it.

With this approach, you decouple the recognition of special value types from the deserialization, avoid making the deserializers parse your prefix, and the idea is extensible to any type that doesn’t have an intrinsic format in JSON.

richardtallent commented Jun 10, 2018

Don’t make consumers look inside the value to determine the type. Pass an object with explicit type and value keys. Or even an object with a single key, the type, ie:

params: [
{ serialized: true, dateTime: “...” }
{ serialized: true, base64: “...” },
// probably better to do this:
{ serialized: true, encoding: “iso8601”, value: “2018...” },
{ serialized: true, encoding: “base64”, value: “...” }
]

Typing on my phone, apologies for formatting. Basically pass an object that the consumer can quickly identify as a serialized string so it can pass it to the appropriate code to deserialize it.

With this approach, you decouple the recognition of special value types from the deserialization, avoid making the deserializers parse your prefix, and the idea is extensible to any type that doesn’t have an intrinsic format in JSON.

@scripting

This comment has been minimized.

Show comment
Hide comment
@scripting

scripting Jun 11, 2018

Richard, the consumers wouldn't have to look inside the value to get the type, because that would be handled by the toolkit, as it is in XML-RPC's XML serialization.

JSON doesn't have a way of representing dates and binary info, but JavaScript does.

Owner

scripting commented Jun 11, 2018

Richard, the consumers wouldn't have to look inside the value to get the type, because that would be handled by the toolkit, as it is in XML-RPC's XML serialization.

JSON doesn't have a way of representing dates and binary info, but JavaScript does.

@scripting

This comment has been minimized.

Show comment
Hide comment
Owner

scripting commented Jun 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment