JSON IList Covariance
An Unexpected Roadblock I ran into a an unexpected roadblock the other day when refactoring code that controls JSON de-serialization. It forced me to read up on the dreaded topic of covariance and contravariance in C#. During code review, I was asked to change the technique I used to specify how JSON should be de-serialized into a root type that includes properties typed as interfaces. The conundrum is what classes should be instantiated for these properties? I solved this problem using Json.NET JsonSerializerSettings.TypeNameHandling. This embeds type names into JSON text as properties named “$type”. When the JSON text is de-serialized, […]
The Web Protocol Is the Integration
Last week I had a frustrating debugging session with an integration partner. They provide financial services we’re integrating into our website. They provide these services via a JSON web service endpoint. The Project I have architected a server-to-server solution that enables our server to post and retrieve data to / from their service. This is secured using TLS and JWT. While some integration features are implemented using a client-to-server architecture (and a separate JWT because it’s revealed to the client), the majority of integration features are implemented using a server-to-server architecture with a private JWT. Server-to-Server. Remember that- it’s important […]
Complex Object Graphs, Side Effects, and the Record Pattern
I hope you and your loved ones are doing as well as can be expected in these difficult times. I feel very fortunate to be gainfully employed during the Coronavirus pandemic. Introduction I ran into an interesting coding issue at work I’d like to discuss here. It involves a subtle object reference inequality bug in my implementation of the Record Pattern. At least that’s what we call the pattern at work. To discuss the issue here I’ll change the names of classes to avoid revealing any intellectual property and simplify the code to the minimum necessary to demonstrate the issue […]
The Best Domain-Specific Language for Manipulating Data is SQL
Motivation I’m not a fan of Microsoft’s Language Integrated Query (LINQ). But ranting about a language feature is an ineffective way to convince programmers of the merits of other techniques. So decided to construct a detailed example that illustrates how LINQ solves a certain problem, contrast it with a different technique, then highlight the deficiencies of LINQ and extol the virtues of my preferred technique. I happily set about creating a relational database and C# object model, then hit an impasse. When the time came to determine how to write LINQ code that maps the relational data into the C# […]