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

JSON constructors create values that don't correspond to the original schema

Open Tarmil opened this issue 6 years ago • 2 comments

The constructors provided by JsonProvider can create values in a way that doesn't correspond to the original schema. In particular:

  1. Optional fields are serialized as null rather than absent field:

    type A = JsonProvider<"""[{"a":1,"b":2}, {"a":3}]""">
    
    let a = A.Root(a = 1, b = None).JsonValue.ToString()
    // Expected: {"a":1}
    // Actual:   {"a":1,"b":null}
    
  2. Decimal fields inferred from string are serialized as number:

    type B = JsonProvider<"""{"a":"1.4"}""">
    
    let b = B.Root(a = 3.1m).JsonValue.ToString()
    // Expected: {"a":"3.1"}
    // Actual:   {"a":3.1}
    

Tarmil avatar Jun 13 '19 08:06 Tarmil

Same problem here for option an json strings (double quotes surrounded values)

cboudereau avatar Oct 02 '19 12:10 cboudereau

Same problem on #1245

joshuapassos avatar Oct 11 '19 04:10 joshuapassos