Project

General

Profile

Task #27243

Implement Optional type to handle optional fields in web service requests

Added by Sachin Divekar about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Target version:
-
Start date:
05/05/2025
Due date:
% Done:

0%

Estimated time:

Description

We need a way to distinguish between fields that were explicitly provided in JSON requests and fields that were omitted entirely. We used to use pointers to identify this but using generics we can design a simple solution. Optional[T] type with a custom unmarshaler can correctly detects when a field is provided vs not provided in JSON and provide simple way to identify and get the value correctly compared to handling pointers.

#1

Updated by Sachin Divekar about 1 month ago

  • Status changed from New to In Progress
#2

Updated by Sachin Divekar about 1 month ago

Added a generic Optional type to the wscutils package that helps distinguish between fields that were explicitly provided in a JSON request (even with zero values) and fields that were not provided at all. It tracks field presence, handles null values, and provides a convenient Get() method for safely accessing values.

  • Written tests
  • Written examples and tutorial
#3

Updated by Sachin Divekar about 1 month ago

  • Status changed from In Progress to Testing
#4

Updated by Sachin Divekar about 1 month ago

  • Status changed from Testing to Closed

Also available in: Atom PDF