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

support for arbitrary maps and sequences #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Niedzwiedzw
Copy link

This is needed for serde-transcode to work properly when encoding an arbitrary serde-deserializable format into xml using your crate. Serde formats are supposed to support that in any shape or form according the serde docs https://serde.rs/transcode.html
Previous behaviour was to just panic.

@elmarco
Copy link

elmarco commented May 6, 2020

I ran exactly on this error yesterday, and I can confirm your fix works for me. Good to merge imho, thanks :)

@elmarco
Copy link

elmarco commented Jul 23, 2020

Hi @punkstarman any chance you look at it? thanks

Copy link
Collaborator

@punkstarman punkstarman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution. The serialization part of this library is still lacking many features, so your help is very welcome.

In order to make the contribution shipshape, please make the changes I recommend or respond with counterarguments.

@@ -16,3 +16,5 @@ thiserror = "1.0"
serde_derive = "1.0"
simple_logger = "1.0.1"
docmatic = "0.1.2"
serde_json = "1.0"
serde-transcode = "1.1.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not have these dependencies, even if they are only used for testing.

I believe that the same behaviour can be specified and tested in the next larger context.

@@ -150,6 +150,7 @@ fn test_doctype() {
}

#[test]
#[ignore]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test ignored?

I suggest that

  • either it should be made to pass
  • or it should be modified because the behaviour is impacted by the change
  • or it should be removed with an explanation as to why the behaviour cannot be changed without taking it beyond recognition

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's failing man, try tunning it on master

@@ -1,6 +1,7 @@
extern crate docmatic;

#[test]
#[ignore]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, tests should not be ignored in a pull request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's failing on master branch, try it

serde_transcode::transcode(deserializer, &mut serializer)?;
Ok(String::from_utf8(out)?)
}
fn _to_json<'a>(deserializer: impl Deserializer<'a>) -> Result<String, Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree with this style of preceding a function name with an underscore in this context.

I suggest removing the initial underscore from the function name.

@@ -159,3 +161,24 @@ fn collection_of_enums() {
}
);
}

fn _to_xml<'a>(deserializer: impl Deserializer<'a>) -> Result<String, Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree with this style of preceding a function name with an underscore in this context.

I suggest removing the initial underscore from the function name.


// fn is_human_readable(&self) -> bool {
// false
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never submit commented code in a pull request.

Please remove this.

let mut deserializer = serde_json::de::Deserializer::from_str(example_json);
let xml = _to_xml(&mut deserializer).expect("failed to transcode json into xml");
assert_eq!(r##"<map><field fieldName="Asdasd"><list><item>asdadsda</item></list></field></map>"##.to_string(), xml)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I would rather not rely on serde_json or serde_transcode to specify and test the behaviour introduced by this pull request. I believe that the same goal can be accomplished by considering a slightly more general context. This kind of test does have value for checking a specific outcome quickly, but I don't believe that they belong in the final version.

I suggest simply adding a test for the list case, similar to test_serialize_simple_map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants