Skip to content

serde_as does not process enum variant attributes #499

@l-2-j

Description

@l-2-j

In my attempt to update to [email protected] I noticed that nested JSON support is gone, with a changelog stating that:

json::nested can be replaced with #[serde_as(as = "json::JsonString")].

It doesn't seem quite as simple as that though, as I can't figure out a way to achieve what worked with json::nested using JsonString.

Minimal example which contains example JSON files and tests: https://github.com/ljoonal/serde_with_nested_json

running 4 tests
test enum_nested_json ... ok
test struct_json_string ... ok
test enum_json_string ... FAILED
test struct_nested_json ... ok

failures:

---- enum_json_string stdout ----
thread 'enum_json_string' panicked at 'called Result::unwrap() on an Err value: Error("invalid type: string "{\"id\":\"R-5c5d3057-bb97-4c31-a2e0-26ea055b2bcf\"}", expected struct MessagePayload", line: 6, column: 2)', src/lib.rs:32:70

My expectation is that JsonString should work just like json:nested did, but instead it fails for a reason that is beyond my debugging skills. But I've at least narrowed it down to working with the structs but breaking with the enums in the linked example repo.

As to why support for this would be nice, a real world usecase is de-serializing an external JSON API's responses that contain nested json of different types, but also sometimes just plain strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions