serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.85k stars 555 forks source link

Recover raw values after losing the type #1148

Closed IvanUkhov closed 3 months ago

IvanUkhov commented 3 months ago

Hello,

I have a use case where a struct with a raw value gets converted into a Value, which then needs to be serialized to JSON. Upon conversion, RawValue gets downcast to a Map, which loses the special serialization of RawValue, resulting in a JSON containing an object with one entry whose key equals raw::TOKEN.

I am wondering if you would be willing to have code for recovering the “rawness.”

IvanUkhov commented 3 months ago

It was a good question that made me think a little bit harder. After going back and forth, I have decided to propose a similar change to async-graphql instead, which was the use case I mentioned:

https://github.com/async-graphql/async-graphql/pull/1554