Skip to content

Serialization of optional record fields when value is of non-primitive type and is None #150

@alex35mil

Description

@alex35mil
module Inner = {
  @schema
  type t = {k: int}
}

module OuterInt = {
  @schema
  type t = {int?: @s.null option<int>}
}

module OuterRecord = {
  @schema
  type t = {record?: @s.null option<Inner.t>}
}

let int = {OuterInt.int: None}
let record = {OuterRecord.record: None}

let intJson = int->S.reverseConvertToJsonOrThrow(OuterInt.schema)->Js.Json.stringify
let recordJson = record->S.reverseConvertToJsonOrThrow(OuterRecord.schema)->Js.Json.stringify

intJson->Js.log2("Int JSON:", _)
recordJson->Js.log2("Record JSON:", _)

Expected output:

Int JSON: {"int":null}
Record JSON: {"record":null}

Actual output:

Int JSON: {"int":null}
Record JSON: {"record":{"BS_PRIVATE_NESTED_SOME_NONE":0}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions