コード例 #1
0
        private PomonaJsonSerializer GetSerializer()
        {
            var serializerFactory = new PomonaJsonSerializerFactory();
            var nancyContext      = new NancyContext {
                Request = new Request("Get", "http://test")
            };
            var uriResolver     = new UriResolver(this.typeMapper, new BaseUriProvider(nancyContext, "/"));
            var contextProvider = new ServerSerializationContextProvider(this.typeMapper,
                                                                         uriResolver,
                                                                         Substitute.For <IResourceResolver>(), new NoContainer());
            var serializer = serializerFactory.GetSerializer(contextProvider);

            return(serializer);
        }
コード例 #2
0
        private JObject SerializeAndGetJsonObject <T>(T value)
        {
            var serializerFactory =
                new PomonaJsonSerializerFactory();
            var pomonaClient = Substitute.For <IPomonaClient>();
            var serializer   = serializerFactory.GetSerializer(
                new ClientSerializationContextProvider(this.typeMapper, pomonaClient, pomonaClient));

            Console.WriteLine("Serialized object to json:");
            string jsonString;

            using (var stringWriter = new StringWriter())
            {
                serializer.Serialize(stringWriter, value, null);
                jsonString = stringWriter.ToString();
            }
            Console.WriteLine(jsonString);

            return((JObject)JToken.Parse(jsonString));
        }