Allow JsonTransformingSerializer
to take a nullable type
#2980
Labels
JsonTransformingSerializer
to take a nullable type
#2980
What is your use-case and why do you need this feature?
An API could accept strings that are nullable, but when non-null, must not be empty/blank, however, API users (such as forms in websites) can send empty/blank strings, which are invalid.
To prevent issues, I would like to map empty/blank strings to
null
before deserializing, I believe I can useJsonTransformingSerializer
to do this like so:However this will throw
Expected string value for a non-null key 'primitive', got null literal instead at element: $.primitive<EOL>JSON input: null]
I tried to reproduce a working sample by copying
JsonTransformingSerializer
's code, and I got it working by only adding.nullable
on the serializer, like so:Describe the solution you'd like
I believe removing the
Any
bound on the type parameter would allow users to passString.serializer().nullable
, this should not require any further changesThe text was updated successfully, but these errors were encountered: