question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I configure JSON serializer

See original GitHub issue

I need to configure JSON serializer below this code doesn’t work

services.Configure<MvcJsonOptions>(jsonOptions =>
{
	jsonOptions.SerializerSettings.ContractResolver = new UnixTimeContractResolver
	{
		NamingStrategy = new CamelCaseNamingStrategy()
	};
});

I checked the sourcecode in AbpServiceCollectionExtensions , I see the code like below

public static IServiceProvider AddAbp<TStartupModule>(this IServiceCollection services, [CanBeNull] Action<AbpBootstrapperOptions> optionsAction = null)
	where TStartupModule : AbpModule
{
	var abpBootstrapper = AddAbpBootstrapper<TStartupModule>(services, optionsAction);

	ConfigureAspNetCore(services, abpBootstrapper.IocManager);

	return WindsorRegistrationHelper.CreateServiceProvider(abpBootstrapper.IocManager.IocContainer, services);
}

private static void ConfigureAspNetCore(IServiceCollection services, IIocResolver iocResolver)
{
	//....

	//Configure JSON serializer
	services.Configure<MvcJsonOptions>(jsonOptions =>
	{
		jsonOptions.SerializerSettings.ContractResolver = new AbpContractResolver
		{
			NamingStrategy = new CamelCaseNamingStrategy()
		};
	});

	//Configure MVC

	//Configure Razor
}

so, I can’t override Configure JSON serializer

in abp 3.3, this issue https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2764 is work, but it doesn’t work now, my version is AbpCore 3.6.1

please help me, thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amin168commented, Jun 1, 2018

@ismcagdas thank very much,it’s work. 😁

0reactions
lockcdcommented, Mar 4, 2020

It’s work for me.

services.PostConfigure<MvcNewtonsoftJsonOptions>(options => { options.SerializerSettings.ContractResolver = new MyContractResolver() { NamingStrategy = new CamelCaseNamingStrategy() }; options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; });

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set json serializer settings in asp.net core 3?
Gets or sets a function that creates default JsonSerializerSettings. Default settings are automatically used by serialization methods on ...
Read more >
How to instantiate JsonSerializerOptions with System.Text. ...
Reuse the same instance for every call. This guidance applies to code you write for custom converters and when you call JsonSerializer.Serialize ......
Read more >
Serialization Settings
A JsonConverter allows JSON to be manually written during serialization and read during deserialization. This is useful for particularly complex ...
Read more >
ASP.NET Core JSON Serialization - Documentation - Telerik
Configure JSON Serialization in ASP.NET Core 2. To maintain the property names casing, locate the ConfigureServices method and update it by adding the...
Read more >
Using multiple JSON serialization settings in ASP.NET Core
First, we need a way to specify multiple JSON serialization settings, and access these settings by name. Fortunately, ASP.NET Core got us ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found