public override TEnumValueObject Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var jsonString = reader.GetString(); var result = EnumValueObject <TEnumValueObject> .Create(jsonString); if (result.IsFailure) { throw new ArgumentException($"Could not transform to type {typeof(TEnumValueObject).Name} from key: {jsonString}"); } return(result.Value); }
public override TEnumValueObject ReadJson(JsonReader reader, Type objectType, TEnumValueObject existingValue, bool hasExistingValue, JsonSerializer serializer) { var key = reader.Value as string; if (string.IsNullOrEmpty(key)) { return(null); } var result = EnumValueObject <TEnumValueObject> .Create(key); if (result.IsFailure) { throw new ArgumentException($"Could not transform to type {typeof(TEnumValueObject).Name} from key: {key}"); } return(result.Value); }