Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple external field names #61

Closed
hugoduncan opened this issue Apr 21, 2015 · 4 comments
Closed

Multiple external field names #61

hugoduncan opened this issue Apr 21, 2015 · 4 comments

Comments

@hugoduncan
Copy link
Contributor

I'm using serde to interact with Amazon's EC2 API. The API uses url-encoded parameters on input and returns XML. I am using serde for both serialisation and deserialisation. However, the field names expected by EC2 on input are different from the field names returned in the XML.

I can see several ways of solving this:
a) Extend serde to allow renaming fileds differently on serialisation and on deserialisation, possibly via rename_ser and rename_de annotations.
b) Extend serde to allow Serialiser specific field encodings.
c) Create parallel data structures for input and output data.

Option c) obviously does not require any change in serde, but I'm reluctant to go this route, as it involves significant extra code (there are approx 650 structs used in the EC2 api), particularly in order to hide the duplication in the exposed api, and compile times are already awful (>5mins).

Option a) seems relatively simple to implement, but adds some complexity to serde. Cognitive complexity can be limited by keeping the rename annotation for the case where the field names are identical for both serialisation and deserialisation.

Option b) seems the most flexible, but would probably add more complexity to serde, espescially for implementors of Serializer, and would likely incur extra runtime overhead.

Would either of a) or b) be considered for serde?

@erickt
Copy link
Member

erickt commented Apr 21, 2015

Of course EC2 would have inconsistent names. Why make things simple for us?

So (a) looks good in general, though it's a bit strange that we can't roundtrip the format using this scheme. Do you think if we had specialization it could work for this?

And yuck! 5 minutes? That could be a useful stress test to help optimize the type checker. Do you have it online somewhere?

@hugoduncan
Copy link
Contributor Author

I pushed the rust AWS lib. Note this is still very much a work in progress. It depends on #62 and #39.

hugoduncan added a commit to hugoduncan/rust-serde that referenced this issue Apr 28, 2015
Allows different field names to be used for different external formats.

Field names are specified using the `rename` field attribute, e.g:

    #[serde(rename(xml= "a4", json="a5"))]

Reverts serde-rs#62

Addresses serde-rs#61
hugoduncan added a commit to hugoduncan/rust-serde that referenced this issue May 14, 2015
Allows different field names to be used for different external formats.

Field names are specified using the `rename` field attribute, e.g:

    #[serde(rename(xml= "a4", json="a5"))]

Reverts serde-rs#62

Addresses serde-rs#61
@erickt
Copy link
Member

erickt commented May 19, 2015

@hugoduncan: #69 landed, so is this safe to close?

@hugoduncan
Copy link
Contributor Author

I think so.

erickt added a commit to erickt/serde that referenced this issue Feb 8, 2016
…d deserializing

According to serde-rs#61, if one uses serde to serialize requests that pass
url-encoded parameters to a server, it might get responses back
with a different capitalization scheme. This patch restores the
behavior implemented in serde-rs#61.
erickt added a commit to erickt/serde that referenced this issue Feb 8, 2016
…d deserializing

According to serde-rs#61, if one uses serde to serialize requests that pass
url-encoded parameters to a server, it might get responses back
with a different capitalization scheme. This patch restores the
behavior implemented in serde-rs#62.
erickt added a commit to erickt/serde that referenced this issue Feb 8, 2016
…d deserializing

According to serde-rs#61, if one uses serde to serialize requests that pass
url-encoded parameters to a server, it might get responses back
with a different capitalization scheme. This patch restores the
behavior implemented in serde-rs#62.

# Conflicts:
#	serde_codegen/src/attr.rs
#	serde_codegen/src/de.rs
#	serde_tests/tests/test_annotations.rs
rubdos pushed a commit to rubdos/serde that referenced this issue Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants