Skip to content

Crash when Serializing #3

@Spinks90

Description

@Spinks90

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions