Skip to content

Parsing schema from string when compiled to NativeAOT with net8 #532

@jdtcn

Description

@jdtcn

Nuget Package

Json.More.Net

Package Version

1.9.0

Can this library make doing something simpler?

Hello!

Thanks for the cool library, that it is powered by System.Text.Json. Recently I tried to use this library in a net 8 application compiled in NativeAOT, and everything works if you do JsonSchemaBuilder().FromType<T>().Build();

Then I tried parsing the schema from the file as JsonSchema.FromText(schema, options); but this unfortunately doesn't work in NativeAOT, there are two problems:

  • You need to create a custom converter for type JsonConverter<Dictionary<string, JsonSchema>> - that's pretty simple and after that the second problem occurs -

  • Method Copy In file json-everything/Json.More/JsonNodeExtensions.cs:195 calls Deserialize without passing there JsonSerializerOptions options that are used to work in NativeAOT, and it fails InvalidOperationException(JsonSerializerIsReflectionDisabled). This happens when calling GetConstraint from ExamplesKeyword.

It would be great if you could pass the JsonSerializerOptions options parameter in there, in this case your library will be able to parse schemas from string in NativeAOT mode.

Thanks!

Describe alternatives you've considered.

No response

Is there any other information you'd like to share regarding this enhancement?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions