예제 #1
0
        internal JsonValue Serialize(SerializationContext context)
        {
            _callCount++;
            var serializer = SerializerFactory.GetSerializer(context);
            var json       = serializer.Serialize(context);

            if (--_callCount == 0)
            {
                context.SerializationMap.Clear();
            }
            return(json);
        }
예제 #2
0
        internal object Deserialize(SerializationContext context)
        {
            _callCount++;
            var serializer = SerializerFactory.GetSerializer(context);
            var obj        = serializer.Deserialize(context);

            if (--_callCount == 0)
            {
                context.SerializationMap.Complete(obj);
            }
            return(obj);
        }
예제 #3
0
        /// <summary>
        /// Deserializes a JSON structure to an object of the appropriate type.
        /// </summary>
        /// <typeparam name="T">The type of the object that the JSON structure represents.</typeparam>
        /// <param name="json">The JSON representation of the object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="TypeDoesNotContainPropertyException">Optionally thrown during automatic
        /// deserialization when the JSON contains a property which is not defined by the requested
        /// type.</exception>
        public T Deserialize <T>(JsonValue json)
        {
            _callCount++;
            var serializer = SerializerFactory.GetSerializer(typeof(T), this, json);
            var obj        = serializer.Deserialize <T>(json, this);

            if (--_callCount == 0)
            {
                SerializationMap.Clear();
            }
            return(obj);
        }
예제 #4
0
        /// <summary>
        /// Serializes an object to a JSON structure.
        /// </summary>
        /// <typeparam name="T">The type of the object to serialize.</typeparam>
        /// <param name="obj">The object to serialize.</param>
        /// <returns>The JSON representation of the object.</returns>
        public JsonValue Serialize <T>(T obj)
        {
            _callCount++;
            var serializer = SerializerFactory.GetSerializer(obj?.GetType() ?? typeof(T), this);
            var json       = serializer.Serialize(obj, this);

            if (--_callCount == 0)
            {
                SerializationMap.Clear();
            }
            return(json);
        }
        internal JsonValue Serialize(SerializationContext context)
        {
            _callCount++;
            Log.Serialization(() => $"Serializing {context.CurrentLocation}");
            var serializer = SerializerFactory.GetSerializer(context);
            var json       = DefaultValueSerializer.Instance.TrySerialize(serializer, context);

            if (--_callCount == 0)
            {
                Log.Serialization(() => "Serialization complete; clearing reference map");
                context.SerializationMap.Clear();
            }
            return(json);
        }
        internal object?Deserialize(DeserializationContext context)
        {
            _callCount++;
            var serializer = SerializerFactory.GetSerializer(context);
            var obj        = SchemaValidator.Instance.TryDeserialize(serializer, context);

            if (--_callCount == 0)
            {
                Log.Serialization(() => "Primary deserialization complete; processing references");
                if (obj != null)
                {
                    context.SerializationMap.Complete(obj);
                }
            }
            return(obj);
        }