media-io / yaserde

Yet Another Serializer/Deserializer
MIT License
175 stars 57 forks source link

Allow adding the 'text' attribute to Option<String> #111

Closed ephraimkunz closed 3 years ago

ephraimkunz commented 3 years ago

I use several of the same Rust structs for both JSON and XML serialization. I need certain properties in these structs to be optional for JSON serialization, but use the "text" attribute for XML. Previously this wasn't possible as yaserde didn't support the "text" attribute on anything but String and types that implemented Into<TokenStream>.

This PR adds support for serializing / deserializing the "text" of an XML tag into Option<String>.

Serialization

If an Option<String> is None, an empty string (the String Default impl) is written. If an Option<String> is Some, the inner string is written.

Deserialization

If the XML text is an empty string, None is produced. Else, Some<text> is produced.

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 276


Changes Missing Coverage Covered Lines Changed/Added Lines %
yaserde_derive/src/lib.rs 0 2 0.0%
yaserde_derive/src/ser/expand_struct.rs 0 3 0.0%
yaserde_derive/src/de/expand_struct.rs 0 5 0.0%
<!-- Total: 14 24 58.33% -->
Totals Coverage Status
Change from base Build 272: 0.1%
Covered Lines: 1138
Relevant Lines: 1905

💛 - Coveralls
ephraimkunz commented 3 years ago

Any ideas if / when someone could take a look at this PR? No huge rush, but I'm working on a library that depends on these changes and I'd like to avoid having to publish a fork of yaserde if possible.