public object DeserializeObject(JsonReader reader, IJsonSerializeOperationInfo info, string path)
        {
            if (!reader.ReadContent(path))
            {
                if (reader.NodeType == JsonNodeType.EndOfString)
                {
                    throw new MalformedDocumentException(MalformedDocumentError.MissingValue,
                                                         path, reader.Line, reader.Position);
                }

                Debug.Assert(reader.NodeType == JsonNodeType.Invalid);

                if (reader.Value is string)
                {
                    throw GetMissingCloseQuoteException(reader, path);
                }

                throw GetMissingOpenQuoteException(reader, path);
            }

            if (_encrypt)
            {
                var toggler = new DecryptReadsToggler(reader, path);
                toggler.Toggle();

                switch (reader.NodeType)
                {
                case JsonNodeType.Number:
                case JsonNodeType.String:
                case JsonNodeType.Boolean:
                    break;

                case JsonNodeType.EndOfString:
                    throw new MalformedDocumentException(MalformedDocumentError.MissingValue,
                                                         path, reader.Line, reader.Position);

                case JsonNodeType.Invalid:
                    if (reader.Value is string)
                    {
                        throw GetMissingCloseQuoteException(reader, path);
                    }

                    throw GetMissingOpenQuoteException(reader, path);

                default:
                    throw GetMissingOpenQuoteException(reader, path);
                }

                try
                {
                    return(Read(reader, info, path));
                }
                finally
                {
                    toggler.Revert();
                }
            }

            return(Read(reader, info, path));
        }
        public object DeserializeObject(JsonReader reader, IJsonSerializeOperationInfo info)
        {
            if (!reader.ReadContent())
            {
                throw new XSerializerException("Unexpected end of input while attempting to parse '{' character.");
            }

            if (reader.NodeType == JsonNodeType.Null)
            {
                return(null);
            }

            if (_encrypt)
            {
                var toggler = new DecryptReadsToggler(reader);
                toggler.Toggle();

                try
                {
                    return(Read(reader, info));
                }
                finally
                {
                    toggler.Revert();
                }
            }

            return(Read(reader, info));
        }
        public object DeserializeObject(
            JsonReader reader, IJsonSerializeOperationInfo info, string path)
        {
            if (!reader.ReadContent(path))
            {
                if (reader.NodeType == JsonNodeType.Invalid)
                {
                    throw new MalformedDocumentException(MalformedDocumentError.InvalidValue,
                                                         path, reader.Value, reader.Line, reader.Position);
                }

                Debug.Assert(reader.NodeType == JsonNodeType.EndOfString);

                throw new MalformedDocumentException(MalformedDocumentError.MissingValue,
                                                     path, reader.Value, reader.Line, reader.Position);
            }

            if (_encrypt)
            {
                var toggler = new DecryptReadsToggler(reader, path);
                if (toggler.Toggle())
                {
                    if (reader.NodeType == JsonNodeType.Invalid)
                    {
                        throw new MalformedDocumentException(MalformedDocumentError.InvalidValue,
                                                             path, reader.Value, reader.Line, reader.Position);
                    }

                    var exception = false;

                    try
                    {
                        return(Read(reader, info, path));
                    }
                    catch (MalformedDocumentException)
                    {
                        exception = true;
                        throw;
                    }
                    finally
                    {
                        if (!exception)
                        {
                            if (reader.NodeType != JsonNodeType.Null && reader.DecryptReads && (reader.ReadContent(path) || reader.NodeType == JsonNodeType.Invalid))
                            {
                                throw new MalformedDocumentException(MalformedDocumentError.ExpectedEndOfDecryptedString,
                                                                     path, reader.Value, reader.Line, reader.Position, null, reader.NodeType);
                            }

                            toggler.Revert();
                        }
                    }
                }
            }

            return(Read(reader, info, path));
        }
Beispiel #4
0
        public object DeserializeObject(JsonReader reader, IJsonSerializeOperationInfo info)
        {
            if (!reader.ReadContent())
            {
                throw new XSerializerException("Reached end of stream while parsing boolean value.");
            }

            if (_encrypt)
            {
                var toggler = new DecryptReadsToggler(reader);
                toggler.Toggle();

                try
                {
                    return(Read(reader));
                }
                finally
                {
                    toggler.Revert();
                }
            }

            return(Read(reader));
        }