简体   繁体   中英

Uppercase key value returned as lowercase in HTTP response

In the backend (.net core) I'm making dictionary:

在此处输入图片说明

key can be 'TEST', testAAAA', 'test', 'TEst' all possible variations.

However this specific result is returned as (image is from postman): 在此处输入图片说明

as you see key here is 'mo' instead of 'MO' . Is it possible to make it case sensitive? so that it wouldn't be made lowercase?

in my startup.cs class I have:

                opt =>
                {
                    opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                    opt.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
                  //  opt.SerializerSettings.Converters.Add(new UnixDateTimeConverter());
                    opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                });
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opt.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });

You're specifically feeding in a resolver and a converter that is telling it to update the casing to camelCase - both incoming and outgoing.

You'll need to change your settings to have it not do that, or you'll need to implement a custom resolver that does different things depending on the class.

You can see some examples of custom resolvers here in the newtonsoft documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM