1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-21 20:43:29 +01:00

Allow static json converters to write null values

This commit is contained in:
Ell 2024-07-19 21:35:47 +02:00
parent 498e1d8fe6
commit ecc0c3b963
2 changed files with 6 additions and 2 deletions

View file

@ -63,7 +63,7 @@ Improvements
### MLEM.Data
Improvements
- **Moved extension methods into matching namespaces to avoid unexpected suggestions**
- Allow static json converters to throw an exception if a key does not exist
- Allow static json converters to write null values and to throw an exception if a key does not exist
Removals
- **Removed obsolete types DynamicEnumConverter, CopyExtensions, DynamicEnum, NetBufferSerializer, and NetExtensions**

View file

@ -58,8 +58,12 @@ namespace MLEM.Data.Json {
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer) {
if (value == null) {
writer.WriteNull();
return;
}
if (!this.inverse.TryGetValue(value, out var key))
throw new InvalidOperationException($"Cannot write {value} that is not a registered entry");
throw new KeyNotFoundException($"Cannot write {value} that is not a registered entry");
writer.WriteValue(key);
}