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.

Bug: custom serializer settings are ignored

See original GitHub issue

When setting custom serialization settings on JsonApiOptions, they are not used. In our scenario we have a few enums exposed as attributes and we want them to serialize into their text representation instead of numeric.

Example:

public enum ScreenOrientation
{
    Horizontal, Vertical
}

public class DemoResource : Identifyable
{
    [Attr]
    public ScreenOrientation Orientation { get; set; }
}

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddJsonApi<AppDbContext>(options =>
        {
            options.SerializerSettings.Converters = new List<JsonConverter>
            {
                new StringEnumConverter()
            };
        });
    }
}

Putting [JsonConverter(typeof(StringEnumConverter))] on ScreenOrientation works, but the global setting does not.

Using the global setting should work, according to https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/docs/usage/options.md#custom-serializer-settings.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bart-degreedcommented, Feb 19, 2020

Update: After discussion, we decided to keep the Newtonsoft.Json setting and remove ISerializerOptions.

0reactions
bart-degreedcommented, Feb 20, 2020

To clarify: The work that needs to be done here, in additional to the changes in #688, is to remove the JsonApiDotNetCore.Configuration.ISerializerOptions interface and update its usages to use Newtonsoft.Json.JsonSerializerSettings instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IJSRuntime ignores custom json serializer in server side ...
I first serialized my object with json.net so I could define NullValueHandling = NullValueHandling.Ignore and so all the custom converters ...
Read more >
How to ignore properties with System.Text.Json
To ignore individual properties, use the [JsonIgnore] attribute. The following example shows a type to serialize. It also shows the JSON ...
Read more >
The Serializer Component (Symfony Docs)
All attributes are included by default when serializing objects. There are two options to ignore some of those attributes. Option 1: Using @Ignore...
Read more >
Bug: Files opened in append mode should not be used ...
Members ignored during record serialization should not be used. Bug ... AssertJ methods setting the assertion context should come before an assertion. Bug ......
Read more >
Json ignore property javascript. Use the unsafe encoder only
Overview This tutorial will show how to ignore certain fields when serializing an object to JSON using Jackson 2. Jackson provides an ObjectMapper...
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