fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
222 stars 26 forks source link

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

Open megafinz opened 3 years ago

megafinz commented 3 years ago

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": {
        ...
    }
}
vsapronov commented 3 years ago

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).

megafinz commented 3 years ago

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

vsapronov commented 3 years ago

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

vsapronov commented 3 years ago

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

megafinz commented 3 years ago

Thanks!