Skip to content

Allow JsonSerializerOptions without TypeInfoResolver #1150

@flensrocker

Description

@flensrocker

I have JsonSerializerOptions which only adds some converters and set the naming policy. I don't have a source generated JsonSerializerContext and therefore no TypeInfoResolver.

When passing these options to a WithTools function, I get the exception:

JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.

I understand that making these options read only is a good thing, but I don't understand enough about the difference to the overload of MakeReadOnly(populateMissingResolver) on the options.

I can set TypeInfoResolver = new DefaultJsonTypeInfoResolver() on my options, but that seems a bit weird.

To Reproduce
Steps to reproduce the behavior:

  1. Pass a new System.Text.Json.JsonSerializerOptions() object to one of the WithTools functions.

Expected behavior
No exception should be thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions