TypedocConverter icon indicating copy to clipboard operation
TypedocConverter copied to clipboard

Decorate with both System.Text.Json & Newtonsoft.Json attributes?

Open JBBianchi opened this issue 3 years ago • 2 comments

Hello,

As you may know, TypedocConverter will probably be used a lot for Blazor libraries in order to wrap existing JS/TS projects.

The users of the said Blazor library may vary, some will use it in a context that uses System.Text.Json and some Newtonsoft.Json.

The idea would be to change the arg --use-system-json so it could be something like [true|false|both] for instance.

Wdyt ?

JBBianchi avatar Sep 15 '22 12:09 JBBianchi

What the codegen will be with --use-system-json both? Are you expecting TypedocConverter to generate two bindings that one uses System.Text.Json and another uses Newtonsoft.Json?

hez2010 avatar Sep 15 '22 13:09 hez2010

The idea is to use them both at the same time:

//...
        [System.Text.Json.Serialization.JsonPropertyName("someprop")]
        [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
        [Newtonsoft.Json.JsonProperty(PropertyName = "someprop", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public string? SomeProp{ get; set; } = null;
//...

It's just a suggestion though, I'm not sure. From what I recall, JS interop in Blazor rely on System.Text.Json and it cannot be changed while Newtonsoft.Json might still be "actually" used by the devs on the rest of the app for ease of use regarding certain use-cases.

JBBianchi avatar Sep 15 '22 13:09 JBBianchi

Fixed in a59854487b446bd2211d9667751c9c7bf06bf494

hez2010 avatar Dec 22 '22 02:12 hez2010