Exemplo n.º 1
0
        public override object ReadJson(SpeckleNewtonsoft.Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializer serializer)
        {
            JObject jObject = null;

            jObject = serializer.Deserialize <SpeckleNewtonsoft.Newtonsoft.Json.Linq.JObject>(reader);

            if (jObject == null)
            {
                return(null);
            }

            var discriminator = SpeckleNewtonsoft.Newtonsoft.Json.Linq.Extensions.Value <string>(jObject.GetValue(_discriminator));
            var subtype       = GetObjectSubtypeBetter(jObject, objectType, discriminator);

            try
            {
                _isReading = true;
                return(serializer.Deserialize(jObject.CreateReader(), subtype));
            }
            finally
            {
                _isReading = false;
            }
        }
Exemplo n.º 2
0
 public override void WriteJson(SpeckleNewtonsoft.Newtonsoft.Json.JsonWriter writer, object value, SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializer serializer)
 {
     try
     {
         _isWriting = true;
         var jObject = SpeckleNewtonsoft.Newtonsoft.Json.Linq.JObject.FromObject(value, serializer);
         writer.WriteToken(jObject.CreateReader());
     }
     finally
     {
         _isWriting = false;
     }
 }