Skip to content

Conversation

@xperiandri
Copy link
Collaborator

Imagine you have an address

type AddressRecord = {
    Line1: AddressLine1 Skippable
    Line2: AddressLine2 voption Skippable
    City: City Skippable
    State: State Skippable
    ZipCode: ZipCode Skippable
}

and you want to patch it (apply changes to only particular fields keeping the other untouched).

Then you can send such an input object

{
  "line1": "New value"
  "line2": null // means clear value
  // skip other properties, means do not change them
}

To support this approach we need to be able to recognize if a field is null or missing and to support converting input values into System.Text.Json.Serialization.Skippable where missing value is Skip, null value is Include None/Include ValueNone (when class constructor parameter is Option/ValueOption and Skip otherwise) and value is Include value

See StarWarsApi for usage sample

@xperiandri xperiandri requested a review from valbers December 8, 2024 01:06
@xperiandri
Copy link
Collaborator Author

@njlr @pkese what do you think?

@njlr
Copy link
Contributor

njlr commented Dec 8, 2024

@njlr @pkese what do you think?

LGTM 👍

@pkese
Copy link
Contributor

pkese commented Dec 8, 2024

Yes, it's a good solution. 👍

@xperiandri xperiandri merged commit c184046 into dev Dec 10, 2024
3 checks passed
@xperiandri xperiandri deleted the skippable branch December 10, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants