Skip to content

Union cases based on values other than strings #89

@Happypig375

Description

@Happypig375

I would like to model this:

[
{ "ID":"869E4854AB1A4251A370D482AE008089", "Name":"Item 1", "Type": 1 },
{ "ID":"83491C1E89334D2884E38021FA13A470", "Name":"Item 3", "Type": 1 },
{ "ID":"2E11A606C25D4FF99D08119B6B8E6576", "Name":"Item 8", "Type": 1 },
{ "ID":"EBEBBF9200844AD6B029EC4144174F47", "Name":"Item 12", "Type": 2, "Color": "Red", "Shape": "Circle" },
{ "ID":"647BC6470FD34666AF2DA020A5467B1A", "Name":"Item 2", "Type": 2, "Color": "Green", "Shape": "Rectangle" },
{ "ID":"211CC8D0F80D4EAE8766FF6178266AE9", "Name":"Item 6", "Type": 3, "Price": 150, "Unit": "USD" },
{ "ID":"FFB46CD3530F48A58B3C08DC319CE0D4", "Name":"Item 5", "Type": 3, "Price": 40, "Unit": "GBP" },
]

Basically, there are multiple fields that are included or excluded together depending on the type.
Modelling this with Skippable cannot guarantee that multiple fields must exist or not together,
while modelling this with Untagged throws an exception upon encountering common fields.
The best way to model this is with InternalTag ||| UnwrapRecordCases, but JsonPropertyName only supports strings, instead of bools, ints, floats, and nulls, or even via absence of the case name. I would like to see this supported.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions