Skip to content

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

@Tarmil

Description

@Tarmil

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions