I found out how to use System.Text.Json with immutable objects using the [JsonConstructor] attribute (see: How to use immutable types), and separately how to preserve references