From ebde35b4fd287a0981c21c0bedf81550cf0cf911 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Mon, 5 Jul 2021 15:24:13 -0400 Subject: [PATCH] DreamValue json serialization for `null` --- OpenDreamRuntime/DreamValue.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OpenDreamRuntime/DreamValue.cs b/OpenDreamRuntime/DreamValue.cs index 15d69e784e..9816148788 100644 --- a/OpenDreamRuntime/DreamValue.cs +++ b/OpenDreamRuntime/DreamValue.cs @@ -314,6 +314,7 @@ public override void Write(Utf8JsonWriter writer, DreamValue value, JsonSerializ switch (value.Type) { case DreamValue.DreamValueType.String: writer.WriteString("Value", (string)value.Value); break; case DreamValue.DreamValueType.Float: writer.WriteNumber("Value", (float)value.Value); break; + case DreamValue.DreamValueType.DreamObject when value == DreamValue.Null: writer.WriteNull("Value"); break; default: throw new NotImplementedException("Json serialization for " + value + " is not implemented"); } @@ -336,6 +337,15 @@ public override DreamValue Read(ref Utf8JsonReader reader, Type typeToConvert, J switch (type) { case DreamValue.DreamValueType.String: value = new DreamValue(reader.GetString()); break; case DreamValue.DreamValueType.Float: value = new DreamValue((float)reader.GetSingle()); break; + case DreamValue.DreamValueType.DreamObject when reader.TokenType == JsonTokenType.Null: { + if (reader.TokenType == JsonTokenType.Null) { + value = DreamValue.Null; + } else { + throw new NotImplementedException("Json deserialization for DreamObjects are not implemented"); + } + + break; + } default: throw new NotImplementedException("Json deserialization for type " + type + " is not implemented"); } reader.Read();