Skip to content

Weird behavior serializing byte array to JSON #89024

@vitek-karas

Description

@vitek-karas

System.Text.Json serialization behavior difference of primitive arrays.

image

The exact same object but passed with a different static type will end up being serialized differently. I could understand this happening for polymorphic cases, but this case is just arrays of primitive types. Note that this is specific to a byte array as it serializes to Base64 if recognized as such, all other primitive arrays serialize as arrays of their elements.

I don't think we can change/fix this, but I think it would be interesting to learn why and if this is intentional or not (and if we have tests for this difference).

/cc @eerhardt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions