Example #1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API routes
            config.MapHttpAttributeRoutes();

            config.EnableCors();

            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Formatters.Remove(config.Formatters.JsonFormatter);

            var jsonFormatter = new JilMediaTypeFormatter(JilSerializer.JilOptions);

            //var mp = jsonFormatter.SupportedMediaTypes;
            config.Formatters.Add(jsonFormatter);
        }
Example #2
0
        public async Task Hello()
        {
            var f = new JilMediaTypeFormatter();

            var value = new SomeValues {
                Id   = 10,
                Name = "Elon Musk"
            };

            var stream = new MemoryStream();
            await f.WriteToStreamAsync(value.GetType(), value, stream, null, null);

            stream.Position = 0;

            var result = (SomeValues)await f.ReadFromStreamAsync(typeof(SomeValues), stream, null, null);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Id, Is.EqualTo(value.Id));
            Assert.That(result.Name, Is.EqualTo(value.Name));
        }