davejrodriguez
davejrodriguez
CC#
Created by davejrodriguez on 3/4/2023 in #help
❔ How to Require Property for Serialization?
Hello, I'm working on a library for the Unity game engine that interfaces with an API. Some of the endpoints require the presence of a property for it to be a valid request. I'm using Newtonsoft.Json for my serialization/deserialization. I saw that it had a [JsonProperty(Required = Required.Always)] attribute, but apparently this only restricts deserialization. Is there any way to restrict serialization as well? Looking to throw an exception or something if developer tries to serialize an object without a required property. I'm not attached to Newtonsoft if there is another library that has this functionality. Thanks!
18 replies