FSharp.Json icon indicating copy to clipboard operation
FSharp.Json copied to clipboard

Deserialize union in CaseKeyAsFieldValue mode from JSON with more than 2 fields

Open megafinz opened this issue 4 years ago • 5 comments

Is there any particular reason for this check in deserializeUnion?

if fields.Length <> 2 then
    failDeserialization path <| sprintf "Failed to parse union from record with %i fields, should be 2 fields." fields.Length

I have a JSON with more than two fields but I care just for the key field (union case discriminator) and the value field.

{
    "ignore_this": "yes",
    "ignore_that": "also yes",
    ...,
    "discriminator": "type_1",
    "data": {
        ...
    }
}

megafinz avatar Aug 24 '20 18:08 megafinz

Does data in your example depend on discriminator? You refer to some "value field" that is not in your example (I'm assuming you meant data field).

vsapronov avatar Aug 24 '20 19:08 vsapronov

Yes, sorry, data is the value field (CaseValueField = "data").

megafinz avatar Aug 24 '20 19:08 megafinz

Hmmm, actually from the code it seems that we can safely lift this limitation for number of fields in the object.

vsapronov avatar Aug 24 '20 19:08 vsapronov

Thank you I will let you know here in what release the change is available

vsapronov avatar Aug 24 '20 20:08 vsapronov

Thanks!

megafinz avatar Aug 24 '20 21:08 megafinz