language-ext icon indicating copy to clipboard operation
language-ext copied to clipboard

Asp.net JSON Serialization NewType

Open RollsChris opened this issue 3 years ago • 0 comments

Hi,

We want to use NewType in our project to give strongly typed IDs etc.

We have written custom JSONconverters and placed on the new classes which work fine when using JsonConvert.SerializeObject. But when we try and return a JsonResult by passing the object into Json() in our actions, they are being serialized incorrectly.

With JsonConvert.SerializeObject the out put is "GUIDHERE" (correct) Json(JsonConvert.SerializeObject(CipMakeupHistoryId.New(Guid.NewGuid())), JsonRequestBehavior.AllowGet)

But without, it is {value:"NewGuidHere"}.

Json(CipMakeupHistoryId.New(Guid.NewGuid()), JsonRequestBehavior.AllowGet);

I have tried registering the converter globallly like so:

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new NewTypeConverter());

But its not taking effect.

Just wondering if anyone has any pointers or solved the same issue. Cant see an issues similar which have been reported.

Thanks

RollsChris avatar Oct 22 '21 08:10 RollsChris