예제 #1
0
 public CustomJsonSerializer()
 {
     Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     DateTimeZoneHandling = DateTimeZoneHandling.Local;
     NullValueHandling = NullValueHandling.Ignore;
 }
        public ClientConfiguration()
        {
            UseSsl = false;
            SslPort = 11207;
            ApiPort = 8092;
            DirectPort = 11210;
            MgmtPort = 8091;
            HttpsMgmtPort = 18091;
            HttpsApiPort = 18092;
            ObserveInterval = 10; //ms
            ObserveTimeout = 500; //ms
            MaxViewRetries = 2;
            ViewHardTimeout = 30000; //ms
            SerializationContractResolver = new CamelCasePropertyNamesContractResolver();
            DeserializationContractResolver = new CamelCasePropertyNamesContractResolver();

            PoolConfiguration = new PoolConfiguration();
            BucketConfigs = new Dictionary<string, BucketConfiguration>
            {
                {DefaultBucket, new BucketConfiguration
                {
                    PoolConfiguration = PoolConfiguration
                }}
            };
            Servers = new List<Uri> { _defaultServer };

            //Set back to default
            _serversChanged = false;
            _poolConfigurationChanged = false;
        }
예제 #3
0
        public static void Register(HttpConfiguration config)
        {
            config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            var exceptionHandler = new WikiDownWebApiExceptionHandler();
            config.Services.Replace(typeof(IExceptionHandler), exceptionHandler);

            var formatting = (DevEnvironment.IsDebug) ? Formatting.Indented : Formatting.None;
            var contractResolver = new CamelCasePropertyNamesContractResolver();
            var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff" };

            var jsonSerializerSettings = config.Formatters.JsonFormatter.SerializerSettings;

            jsonSerializerSettings.Formatting = formatting;
            jsonSerializerSettings.ContractResolver = contractResolver;
            jsonSerializerSettings.Converters.Add(dateTimeConverter);

            config.IncludeErrorDetailPolicy = DevEnvironment.IsDebug
                                                  ? IncludeErrorDetailPolicy.Always
                                                  : IncludeErrorDetailPolicy.Default;

            config.MapHttpAttributeRoutes();

            config.EnsureInitialized();
        }
예제 #4
0
 public BrowserJsonFormatter()
 {
     var camelCaseResolver = new CamelCasePropertyNamesContractResolver();
     this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
     this.SerializerSettings.ContractResolver = camelCaseResolver;
     this.SerializerSettings.Formatting = Formatting.Indented;
     // AB: don't really need this: this.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
 }
 public GuidelineJsonSerializerSettings()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     TypeNameHandling = TypeNameHandling.None;
     DateFormatHandling = DateFormatHandling.IsoDateFormat;
     NullValueHandling = NullValueHandling.Ignore;
     DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate;
     Converters.Add(new StringEnumConverter());
 }
        public JsonSerialisationSettings()
        {
            Converters = new JsonConverter[]
            {
                new StringEnumConverter(),
            };

            ContractResolver = new CamelCasePropertyNamesContractResolver();
        }
        public CustomJsonSerializer()
        {
            // Map C# naming conventions to javascript
            ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Standardize datetime objects
            Converters.Add(new IsoDateTimeConverter
            {
                DateTimeStyles = DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal
            });
        }
예제 #8
0
        public void ToLowerCamelCase_LowerCamelCaser_HasSameBehaviorAsJsonNet(string propertyName, string expectName)
        {
            // Arrange
            var lowerCamelCaser = new LowerCamelCaser();
            var camelCasePropertyNamesContractResolver = new CamelCasePropertyNamesContractResolver();

            // Act
            string nameResolvedByLowerCamelCaser = lowerCamelCaser.ToLowerCamelCase(propertyName);
            string nameResolveByJsonNet = camelCasePropertyNamesContractResolver.GetResolvedPropertyName(propertyName);

            // Assert
            Assert.Equal(nameResolveByJsonNet, nameResolvedByLowerCamelCaser);
            Assert.Equal(expectName, nameResolvedByLowerCamelCaser);
        }
예제 #9
0
        static void CountingLockTest()
        {
            Console.WriteLine("\n Newtonsoft.Json.Serialization.DefaultContractResolver");
            var resolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();

            WriteProps((JsonObjectContract)resolver.ResolveContract(typeof(CountingLock)));

            Console.WriteLine("\n Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver");
            var r = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

            WriteProps((JsonObjectContract)r.ResolveContract(typeof(CountingLock)));

            Console.WriteLine("\n System.Net.Http.Formatting.JsonContractResolver");
            var resolv = new System.Net.Http.Formatting.JsonContractResolver(new Formatter());

            WriteProps((JsonObjectContract)resolv.ResolveContract(typeof(CountingLock)));
        }
		public RestSerializeSettings()
		{
			ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
			PreserveReferencesHandling = PreserveReferencesHandling.None;
			TypeNameHandling = TypeNameHandling.All;
			Formatting = Formatting.None;

			ContractResolver = new CamelCasePropertyNamesContractResolver();

			Converters.Add(new GuidConverter());
			Converters.Add(new ImageConverter());
			Converters.Add(new RestEnumConverter
			{
				AllowIntegerValues = true,
				CamelCaseText = false
			});
		}
예제 #11
0
        // GET: Home
        public async Task<ActionResult> Index()
        {
            TestClass testClass = new TestClass();

            CamelCasePropertyNamesContractResolver rrr = new CamelCasePropertyNamesContractResolver();

            var context = System.Web.HttpContext.Current.Check();
            var syncContext = TaskScheduler.FromCurrentSynchronizationContext();
            await Task.Run(() =>
            {
                var ttt = Thread.CurrentThread;
            });



            //return Content(testClass.ToJson());

            return Json(testClass.ToObject(o => o.Id = 1), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// For synchronization with App.config or Web.configs.
        /// </summary>
        /// <param name="couchbaseClientSection"></param>
        internal ClientConfiguration(CouchbaseClientSection couchbaseClientSection)
        {
            UseSsl = couchbaseClientSection.UseSsl;
            SslPort = couchbaseClientSection.SslPort;
            ApiPort = couchbaseClientSection.ApiPort;
            DirectPort = couchbaseClientSection.DirectPort;
            MgmtPort = couchbaseClientSection.MgmtPort;
            HttpsMgmtPort = couchbaseClientSection.HttpsMgmtPort;
            HttpsApiPort = couchbaseClientSection.HttpsApiPort;
            ObserveInterval = couchbaseClientSection.ObserveInterval;
            ObserveTimeout = couchbaseClientSection.ObserveTimeout;
            MaxViewRetries = couchbaseClientSection.MaxViewRetries;
            ViewHardTimeout = couchbaseClientSection.ViewHardTimeout;
            SerializationContractResolver = new CamelCasePropertyNamesContractResolver();
            DeserializationContractResolver = new CamelCasePropertyNamesContractResolver();

            foreach (var server in couchbaseClientSection.Servers)
            {
                Servers.Add(((UriElement)server).Uri);
            }
            foreach (var bucketElement in couchbaseClientSection.Buckets)
            {
                var bucket = (BucketElement) bucketElement;
                var bucketConfiguration = new BucketConfiguration
                {
                    BucketName = bucket.Name,
                    UseSsl = bucket.UseSsl,
                    Password = bucket.Password,
                    ObserveInterval = bucket.ObserveInterval,
                    ObserveTimeout = bucket.ObserveTimeout,
                    PoolConfiguration = new PoolConfiguration
                    {
                        MaxSize = bucket.ConnectionPool.MaxSize,
                        MinSize = bucket.ConnectionPool.MinSize,
                        WaitTimeout = bucket.ConnectionPool.WaitTimeout,
                        ShutdownTimeout = bucket.ConnectionPool.ShutdownTimeout,
                        UseSsl = bucket.ConnectionPool.UseSsl, 
                    }
                };
                BucketConfigs = new Dictionary<string, BucketConfiguration> {{bucket.Name, bucketConfiguration}};
            }
        }
예제 #13
0
 public CustomJsonSerializer()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     Formatting = Formatting.Indented;
 }
 public CustomJsonSerializer()
 {
     ContractResolver = new CamelCasePropertyNamesContractResolver();
     Converters.Add(new StringEnumConverter());
 }
예제 #15
0
 public PepinoJsonSerializer()
 {
     TypeNameHandling = TypeNameHandling.Objects;
     ContractResolver = new CamelCasePropertyNamesContractResolver();
 }
예제 #16
0
        private string Serialize(object value)
        {
            var resolver = new CamelCasePropertyNamesContractResolver();
            var settings = new JsonSerializerSettings
            {
                ContractResolver = resolver
            };

            settings.Converters.Add(new IsoDateTimeConverter());

            return JsonConvert.SerializeObject(value, Formatting.Indented, settings);
        }
 public CypherExtensionContext()
 {
     JsonContractResolver = new CamelCasePropertyNamesContractResolver();
 }
        public void WithContractResolverShouldValidateOnlyTheProperty()
        {
            var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
            var contractResolver = new CamelCasePropertyNamesContractResolver();
            jsonSerializerSettings.MaxDepth = int.MaxValue;
            jsonSerializerSettings.ContractResolver = contractResolver;

            MyController<MvcController>
                .Instance()
                .WithoutValidation()
                .Calling(c => c.JsonWithSpecificSettingsAction(jsonSerializerSettings))
                .ShouldReturn()
                .Json()
                .WithJsonSerializerSettings(s =>
                    s.WithContractResolver(contractResolver));
        }
예제 #19
0
 public SwaggerDocsContractResolver()
 {
     _camelCasePropertyNamesContractResolver = new CamelCasePropertyNamesContractResolver();
 }