rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
230 stars 29 forks source link

Feature request: Option to serialize read only interface properties #181

Closed KTW-NIRAS closed 6 years ago

KTW-NIRAS commented 6 years ago

I am trying to replace all references to Json.NET in a large MVC / API project, and need a serializer which can output read only properties on interfaces.

Can this be done in NetJSON?

rpgmaker commented 6 years ago

Is this still required? If you enable NetJSON.IncludeTypeInformation then it should include $type for each property. And you can also use NetJSONKnownTypes to specify which class will implement the interface assuming they are user defined or you can make it automatically discover them.

Thanks,

KTW-NIRAS commented 6 years ago

The types are not important in this case, neither is the ability to deserialize. MVC and API controllers are outputting JSON for client side script, and for remote consumption.

It would be nice, if there was an option to treat interfaces like anonymous objects, and just serialize the contents. Type information would be unnecessary overhead in this case.

Is this possible?

rpgmaker commented 6 years ago

Without using the type serialization option, are you getting an exception for interface properties?

Thanks,

KTW-NIRAS commented 6 years ago

Sorry, my bad. :-( I have just tested this on some simple data, and it works out of the box.

Maybe it has to do with serializing circular data then. This might be handled different than by Json.NET.

Thanks for helping. :+1: