PDA

View Full Version : Json serialization issue ?



serkane
Jan 31, 2021, 8:50 PM
is the Ext.Net serialize the object(s) by depending on the options specified at startup ?

actually I tried 2 options shown below but result never changed :(



.AddRazorPages().AddJsonOptions(options => {
options.JsonSerializerOptions.IncludeFields = true;
options.JsonSerializerOptions.DefaultIgnoreConditi on = WhenWritingNull;
})
.AddRazorPages().AddNewtonsoftJson(options => {
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
})


I have a class named XYZ; and wanna return a List<XYZ> to the client on anciton -> OnPostBUTTON_CLICK



public IActionResult OnPostBUTTON_CLICK()
{
var data = new List<XYZ>() {
new XYZ() {field1="val-11", field2= "val-12" },
new XYZ() {field1="val-21", field2= "val-22" }
};

this.X().Call("js-function", data);

return this.Direct();
}


private class XYZ{
public string field1;
public string field2;
}



but at this point seems like Ext.Net does not render the field(s) in class by depending on MVC JsonOptins.

please I'd be liked you to suggest me any idea/offer :)

fabricio.murta
Feb 01, 2021, 10:28 PM
Hello @serkane!

No, it uses its own serializer and whatever you set to ASP.NET / CLR Json won't interfere (and shouldn't) its behavior.

EDIT: the FallbackToStreamRender has nothing to do with the serializer. Instead it is related to how Ext.NET injects code to the generated pages and is used in some scenarios i.e. when the page has no <head /> tag.

Hope this helps!

fabricio.murta
Feb 03, 2021, 2:42 AM
I have received some information here I also didn't know that might help you understand or resolve your issue.

The this.Direct(result) override (when you pass a value to it) does use a regular JsonSerializer to serialize the result value. You get a result field from the response that you could use from a callback event.

the this.X().Call("js-function", data); will use an ISerializationService instance to serialize the data value instead.

Now I can't really go any further because the test code you provided doesn't seem to run without some dependencies. Switching the project to .NET 5 helps with the options.JsonSerializerOptions, but adding Newtonsoft.Json package doesn't add AddNewtonsoftJson() and I have no idea where the WhenWritingNull came from.

If you still need help with this, please provide a code sample that can be run. Also tell us what you expected with either setting (you could add code to do the serialization the way you expected it to work -- maybe just writing it to a temp string var in code behind).

So, for now we cannot tell it is an issue or not, we would need to be able to reproduce the scenario.

Hope this helps!