first commit
This commit is contained in:
21
NitroxServer/Serialization/Json/AttributeContractResolver.cs
Normal file
21
NitroxServer/Serialization/Json/AttributeContractResolver.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace NitroxServer.Serialization.Json;
|
||||
|
||||
public class AttributeContractResolver : DefaultContractResolver
|
||||
{
|
||||
//IDictionary to JsonArray
|
||||
protected override JsonContract CreateContract(Type objectType)
|
||||
{
|
||||
if (objectType.GetInterfaces().Any(i => i == typeof(IDictionary) || i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDictionary<,>)))
|
||||
{
|
||||
return base.CreateArrayContract(objectType);
|
||||
}
|
||||
|
||||
return base.CreateContract(objectType);
|
||||
}
|
||||
}
|
19
NitroxServer/Serialization/Json/NitroxIdConverter.cs
Normal file
19
NitroxServer/Serialization/Json/NitroxIdConverter.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NitroxModel.DataStructures;
|
||||
|
||||
namespace NitroxServer.Serialization.Json
|
||||
{
|
||||
public class NitroxIdConverter : JsonConverter<NitroxId>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, NitroxId value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
|
||||
public override NitroxId ReadJson(JsonReader reader, Type objectType, NitroxId existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
return reader.Value == null ? null : new NitroxId((string)reader.Value);
|
||||
}
|
||||
}
|
||||
}
|
18
NitroxServer/Serialization/Json/TechTypeConverter.cs
Normal file
18
NitroxServer/Serialization/Json/TechTypeConverter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
|
||||
namespace NitroxServer.Serialization.Json
|
||||
{
|
||||
public class TechTypeConverter : JsonConverter<NitroxTechType>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, NitroxTechType value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(value.Name);
|
||||
}
|
||||
public override NitroxTechType ReadJson(JsonReader reader, Type objectType, NitroxTechType existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
return reader.Value == null ? null : new NitroxTechType((string)reader.Value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user