Monday, February 19, 2018

JSON.NET–Resolve private setters

On one of my projects we are using event sourcing as our data persistence strategy. Based on the event stream I build projections using read models.

I prefer to keep my projected read model immutable but turns out that JSON.NET fails to deserialize the state. All properties retain their default values.

A solution is to create a custom contract resolver that uses reflection to set the property values:

Don't forget to apply this contract resolver using the JsonSerializerSettings:

No comments: