public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var converter = new ExpandoObjectConverter();
            var o         = converter.ReadJson(reader, objectType, existingValue, serializer);

            var text = JsonConvert.SerializeObject(o);

            var message = (IMessage)Activator.CreateInstance(objectType);

            var parser = new JsonParser(JsonParser.Settings.Default.WithIgnoreUnknownFields(true));

            return(parser.Parse(text, message.Descriptor));
        }
        public override object ReadJson(JsonReader reader,
                                        System.Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            // Read an entire object from the reader.
            var converter = new ExpandoObjectConverter();
            var o         = converter.ReadJson(reader, objectType, existingValue, serializer);

            // Convert it back to json text.
            var text = JsonConvert.SerializeObject(o);

            // And let protobuf's parser parse the text.
            var message = (IMessage)Activator.CreateInstance(objectType);

            return(JsonParser.Default.Parse(text, message.Descriptor));
        }
Ejemplo n.º 3
0
        public override object ReadJson(JsonReader reader,
                                        Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            // The only way to find where this json object begins and ends is by
            // reading it in as a generic ExpandoObject.
            // Read an entire object from the reader.
            var converter = new ExpandoObjectConverter();
            var o         = converter.ReadJson(reader, objectType, existingValue, serializer);
            // Convert it back to json text.
            var text = JsonConvert.SerializeObject(o);
            // And let protobuf's parser parse the text.
            var message = (IMessage)Activator.CreateInstance(objectType);

            return(JsonParser.Default.Parse(text, message.Descriptor));
        }
Ejemplo n.º 4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var @object = ExpandoObjectConverter.ReadJson(reader, objectType, existingValue, serializer);

            return(DObject.Create((IEnumerable <KeyValuePair <string, object> >)@object));
        }