A base class for resolving how property names and dictionary keys are serialized.
Example #1
0
 public StringEnumConverter(Type namingStrategyType, object[] namingStrategyParameters)
 {
     Class6.yDnXvgqzyB5jw();
     this.AllowIntegerValues = true;
     base();
     ValidationUtils.ArgumentNotNull(namingStrategyType, "namingStrategyType");
     this.NamingStrategy = JsonTypeReflector.CreateNamingStrategyInstance(namingStrategyType, namingStrategyParameters);
 }
Example #2
0
 public StringEnumConverter(Newtonsoft.Json.Serialization.NamingStrategy namingStrategy, bool allowIntegerValues = true)
 {
     Class6.yDnXvgqzyB5jw();
     this.AllowIntegerValues = true;
     base();
     this.NamingStrategy     = namingStrategy;
     this.AllowIntegerValues = allowIntegerValues;
 }
Example #3
0
 public StringEnumConverter(bool camelCaseText)
 {
     Class6.yDnXvgqzyB5jw();
     this.AllowIntegerValues = true;
     base();
     if (camelCaseText)
     {
         this.NamingStrategy = new CamelCaseNamingStrategy();
     }
 }
Example #4
0
        public async Task NamingStrategy_DoesNotAffectSerialization_WithJsonObject(NamingStrategy strategy)
        {
            // Arrange
            var user = new UserWithJsonObject
            {
                age = 35,
                FullName = "John",
            };
            var expected = "{\"age\":35,\"full_name\":\"John\"}";
            var context = GetOutputFormatterContext(user, typeof(UserWithJsonProperty));

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = strategy,
                },
            };
            var formatter = new TestableJsonOutputFormatter(settings);

            // Act
            await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);

            // Assert
            var body = context.HttpContext.Response.Body;

            Assert.NotNull(body);
            body.Position = 0;

            var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
            Assert.Equal(expected, content);
        }
Example #5
0
        public async Task NamingStrategy_DoesNotAffectDictionarySerialization(NamingStrategy strategy)
        {
            // Arrange
            var dictionary = new Dictionary<string, int>(StringComparer.Ordinal)
            {
                { "id", 12 },
                { "Id", 12 },
                { "fullName", 12 },
                { "full-name", 12 },
                { "FullName", 12 },
                { "full_Name", 12 },
            };
            var expected = "{\"id\":12,\"Id\":12,\"fullName\":12,\"full-name\":12,\"FullName\":12,\"full_Name\":12}";
            var context = GetOutputFormatterContext(dictionary, typeof(Dictionary<string, int>));

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = strategy,
                },
            };
            var formatter = new TestableJsonOutputFormatter(settings);

            // Act
            await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);

            // Assert
            var body = context.HttpContext.Response.Body;

            Assert.NotNull(body);
            body.Position = 0;

            var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
            Assert.Equal(expected, content);
        }
Example #6
0
        public async Task NamingStrategy_AffectsSerialization(NamingStrategy strategy, string expected)
        {
            // Arrange
            var user = new User { FullName = "John", age = 35 };
            var context = GetOutputFormatterContext(user, typeof(User));

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = strategy,
                },
            };
            var formatter = new TestableJsonOutputFormatter(settings);

            // Act
            await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);

            // Assert
            var body = context.HttpContext.Response.Body;

            Assert.NotNull(body);
            body.Position = 0;

            var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
            Assert.Equal(expected, content);
        }