Skip to content

Commit

Permalink
DreamValue json serialization for null
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jul 5, 2021
1 parent 43e68a2 commit ebde35b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions OpenDreamRuntime/DreamValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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();
Expand Down

0 comments on commit ebde35b

Please sign in to comment.