Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

.net core 3.0 json camelcase no longer working #83

Closed ganySA closed 5 years ago

ganySA commented 5 years ago

Previously using breeze .net core with .net core 2.2 i could do the following to ensure breeze worked in camelcase mode. However now JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);

No longer works given the shift from the Json Serializer to new .net one?

Any ideas?


 var mvcBuilder = services.AddMvc();

    mvcBuilder.AddJsonOptions(opt => {
        var ss = JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);
        var resolver = ss.ContractResolver;
        if (resolver != null)
        {
            var res = resolver as DefaultContractResolver;
            res.NamingStrategy = null;  // <<!-- this removes the camelcasing
        }

    });
steveschmitt commented 5 years ago

Just to be clear what you want: Something is PascalCase in .net, and you want it to be camelCase when it is JSON serialized, right?

There is this line from your code above:

res.NamingStrategy = null;  // <<!-- this removes the camelcasing

Are you saying that it doesn't work with that line, or without that line, or in neither case?

ganySA commented 5 years ago

They are removing Newtonsoft so they have two configuration options.

The solution is to use AddNewtonsoftJson(opt ==>....) and not AddJsonOptions(opt ==>

AddJsonOptions will use the new microsoft json formatter.

ganySA commented 5 years ago

solution in previous post.

steveschmitt commented 5 years ago

Thanks!

DaljitBhail commented 4 years ago

or :

 services.AddControllers().AddNewtonsoftJson(options =>
        {
            options.SerializerSettings.ReferenceLoopHandling =
                Newtonsoft.Json.ReferenceLoopHandling.Ignore;

            options.UseMemberCasing(); // Use property name instead of default camelcase
        }
        );