Skip to content

Bug: custom serializer settings are ignored #687

Closed
@bart-degreed

Description

@bart-degreed

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions