codecutout/JsonApiSerializer

Does not obey JsonConverter on attribute that isn't part of a resource object

Opened this issue · 2 comments

Version 1.7.4:

A POJO with a nested JsonApi resource (User):

public class AuthenticationResponseDTO
{
    [JsonPropertyName("outcome")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    // AuthenticationOutcome  is an enum
    public AuthenticationOutcome Outcome { get; private set; }

    [JsonPropertyName("tokens")]
    public AuthenticationTokens? Tokens { get; private set; }

    [JsonPropertyName("tenant-permissions")]
    public Dictionary<string, List<string>> tenantPermissions { get; private set; }

    [JsonPropertyName("user")]
    public UserDTO? User { get; private set; }
}

Serializing this results in

{
  outcome: 0
  ...
  user: {data... }
}

Expected:

{
  outcome: "Authenticated"
  ...
  user: {data... }
}

Forked and added tests. Works with the newtonsoft JsonConverter, but not with the System.Text.Json JsonConverter.

Would you like a PR to work with both?

This library only works with the josn.net libraries. I think it is a much bigger piece to get it working using System.Text.Json.

Although both libraries have JsonConverters and they both appear similar, there are enough deeper changes that I don't think supportig System.Text.Json will be a trivial task (although one I would like to happen). But you are more than welcome to take on the challenge