Skip to content

System.Text.Json deserialization of arrays with various types #43670

Closed
@mattchidley

Description

@mattchidley

We're trying to migrate from Newtonsoft to System.Text.Json

We have a test case which checks the roundtrip of serializing an object and then deserializing that result, and comparing the deserialized result back to the original object.

The object in question is:

new object[] { 1.1, 23.0, "sdfsd" }

In both Newtonsoft and System.Text.Json, this is serialized into:

"[1.1,23,"sdfsd"]"

When deserializing the above string, Newtonsoft will return an object[] which matches the original.

System.Text.Json deserializes the above string into an object[] with JsonElements which have a ValueKind and
value. It's important to note that this only occurs when deserializing an object[] with a variety of types.

Is this by design? I haven't been able to find any documentation regarding the expectations here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions