mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
Allow static json converters to write null values
This commit is contained in:
parent
498e1d8fe6
commit
ecc0c3b963
2 changed files with 6 additions and 2 deletions
|
@ -63,7 +63,7 @@ Improvements
|
||||||
### MLEM.Data
|
### MLEM.Data
|
||||||
Improvements
|
Improvements
|
||||||
- **Moved extension methods into matching namespaces to avoid unexpected suggestions**
|
- **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
|
Removals
|
||||||
- **Removed obsolete types DynamicEnumConverter, CopyExtensions, DynamicEnum, NetBufferSerializer, and NetExtensions**
|
- **Removed obsolete types DynamicEnumConverter, CopyExtensions, DynamicEnum, NetBufferSerializer, and NetExtensions**
|
||||||
|
|
|
@ -58,8 +58,12 @@ namespace MLEM.Data.Json {
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <param name="serializer">The calling serializer.</param>
|
/// <param name="serializer">The calling serializer.</param>
|
||||||
public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer) {
|
public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer) {
|
||||||
|
if (value == null) {
|
||||||
|
writer.WriteNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.inverse.TryGetValue(value, out var key))
|
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);
|
writer.WriteValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue