Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when Serializing #3

Open
Spinks90 opened this issue Jul 15, 2024 · 0 comments
Open

Crash when Serializing #3

Spinks90 opened this issue Jul 15, 2024 · 0 comments

Comments

@Spinks90
Copy link

Spinks90 commented Jul 15, 2024

I'm using .NET 8. When I'm trying to serialise the base type, it's crashing. I hoped it would just convert it to the AttributeText due to the PolyJsonConverter.

This is my class

[PolyJsonConverter("attribute_type")]
[PolyJsonConverter.SubType(typeof(AttributeIdentifier), "pim_catalog_identifier")]
[PolyJsonConverter.SubType(typeof(AttributeText), "pim_catalog_text")]
public class AttributeValueBase
{
    [JsonPropertyName("attribute_type")]
    public string AttributeType { get; set; }

    [JsonIgnore]
    public bool IsNew { get; set; }
}

public class AttributeIdentifier : AttributeValueBase
{
    [JsonPropertyName("data")]
    public string Data { get; set; }
}

public class AttributeText : AttributeValueBase
{
    [JsonPropertyName("data")]
    public string Data { get; set; }
}

When I try to serialize it using the base class it crashes:

try
{
    var test = new AttributeValueBase();
    test.AttributeType = "pim_catalog_text";
    test.IsNew = true;

    string json = JsonSerializer.Serialize(test);
}
catch (Exception ex)
{
    throw;
}

I've noticed it's recusively calling the public override void Write(...) method on PolyJsonConverter<T> class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant