Selaa lähdekoodia

Fixed UserProperties serializer

Kenric Nugteren 1 viikko sitten
vanhempi
commit
ffcdd2f084
2 muutettua tiedostoa jossa 9 lisäystä ja 9 poistoa
  1. 7 7
      InABox.Core/Objects/UserProperties.cs
  2. 2 2
      InABox.Core/Serialization.cs

+ 7 - 7
InABox.Core/Objects/UserProperties.cs

@@ -146,15 +146,15 @@ namespace InABox.Core
 
     public class UserPropertiesJsonConverter : CustomJsonConverter<UserProperties>
     {
-
-
         public override void Write(Utf8JsonWriter writer, UserProperties value, JsonSerializerOptions options)
         {
             writer.WriteStartObject();
-            foreach (var key in value.GetKeys())
+            foreach (var (key, val) in value.Dictionary)
             {
-                if (value[key] != null)
-                    writer.WriteString(key, value[key]?.ToString());
+                if (val != null)
+                {
+                    WriteJson(writer, key, val.Value);
+                }
             }
             writer.WriteEndObject();
         }
@@ -162,9 +162,9 @@ namespace InABox.Core
         public override UserProperties? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
         {
             var result = new UserProperties();
-            while (reader.TokenType != JsonTokenType.EndObject && reader.Read())
+            while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
             {
-                var key = reader.GetString();
+                var key = reader.GetString() ?? "";
                 reader.Read();
                 var val = ReadJson(ref reader);
                 result[key] = val;

+ 2 - 2
InABox.Core/Serialization.cs

@@ -956,10 +956,10 @@ namespace InABox.Core
             }
         }
         
-        protected void WriteJson(Utf8JsonWriter writer, string name, object value)
+        protected void WriteJson(Utf8JsonWriter writer, string name, object? value)
         {
             writer.WritePropertyName(name);
-            WriteJson(writer,value);
+            WriteJson(writer, value);
         }
     }