Skip to content

extra::json: Remove or rework ToJson #9028

Closed
@bluss

Description

@bluss

There are two ways to encode values into json in string form, and they can provide different results or be wrong:

  • ToJson transforms a rust value to Json, which can be encoded by a serialize::Encoder
  • json::Encoder implements the Encoder trait, so you can give it arbitrary values, as long as they implement Encodable, and it will output json, or json-like text.

We need to provide a single method of encoding to Json, and make sure we use serialize correctly if we use it.

The ToJson trait expresses the restriction that only maps with string keys can be encoded to Json. This is easy to step around by using the other json encoding method, which results in invalid json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions