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

feat: add support for `losslessOption`

Open MangelMaxime opened this issue 8 months ago • 2 comments

Add ability to support lossless option.

With the current implementation of Thoth.json, None or Some (Some None) are both encoded has null.

This PR introduce 2 new API:

  • lossyOption: is equivalent to the old option API

    / None
    ull
    
    / Some None
    ull
    
    / Some 42
    2
    
    // Some (Some 42)
    2
    
  • losslessOption which is able to differentiate the nested options

    
    / None
    
       "$type": "option",
       "$case": "none"
    
    
    / Some None
    
       "$type": "option",
       "$case": "some",
       "$value": {
           "$type": "option",
           "$case": "none"
       }
    
    
    / Some 42
    
       "$type": "option",
       "$case": "some",
       "$value": 42
    
    
    // Some (Some 42)
    {
        "$type": "option",
        "$case": "some",
        "$value": {
            "$type": "option",
            "$case": "some",
            "$value": 42
        }
    }
    

[!WARNING] The old Decode.option and Encode.option will be completely removed. People, will need to manual path their code to use the lossyOption API.

I am removing the API completely because the API changes only impact the new version of Thoth.Json, so this is I believe the perfect moment to do it instead of introducing an Obsolete warning to be removed later on.

If you think differently please voice int

If we agree on the implementation, we will need to also change the object builder API to reflect this changes too.

MangelMaxime avatar Jun 15 '24 16:06 MangelMaxime