Код: Выделить всё
public class Example {
[JsonIgnore]
public required string RequiredButDontSerialize {get;init;}
public string AnotherPropertyWhatever {get;init;}
}
< /code>
Это заставляет System.text.json бросить ошибку (ниже), когда я пытаюсь ее сериализовать. Я могу абсолютно Guarentee, что я никогда не собираюсь DeSerialze The Type, поэтому я чувствую, что он не должен нуждаться в сеттере (и я получаю одинаковую ошибку с Set
Любые идеи, как я могу сохранить необходимый модификатор, когда убедительно System.json.
Код: Выделить всё
System.InvalidOperationException: JsonPropertyInfo 'target' defined in type 'uk.osric.hooks.models.HookCompletionRecord' is marked required but does not specify a setter.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonPropertyRequiredAndNotDeserializable(JsonPropertyInfo jsonPropertyInfo)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
Подробнее здесь: https://stackoverflow.com/questions/797 ... d-modifier