-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support serializing null on a per field basis - nullable vs required #912
Comments
This gets harder to support with null safety support :) since it forces treating all the JSON as nullable. Once the null safe version is published I can look again at whether there is a good way to resume supporting nulls. |
I saw that null safety is now in a pre version. Why do you think this is harder to support there? This would allow the concept of required but nullable fields in JSON content which is supported by OAS-3.0. |
It's hard because it requires all the serializers to accept nulls; currently they don't, because we never |
I see. Looked into doing this with a serializer plugin but the information would not be available at that point. Maybe additional information like this could somehow be provided in a plugin similar to |
I actually managed to do this with the JsonPlugin by generating custom serializers. With the nullsafe version this is no longer possible since I can not add I am stuck now :/ |
With all the other problems around null-safety like #984 #964 this is somewhat becoming a fundamental question around the wire format that built_value is using/supporting. Json allows for null values, so does the OpenAPI spec and so does Dart now explicitly with null-safety but the native format does not allow it. I assume most people actually use the Maybe it is time to decouple |
Thanks--will think about it when fixing #984 |
Thanks. I think the right direction is to allow more nulls :) In #1001 I open up the interfaces so nulls are allowed in most places, including as top level inputs and outputs, in the serializer plugins and in structured serializer lists. The one exception is that primitive serializers are not allowed to accept or return null. Instead of passing null to a primitive serializer, it is automatically serialized as null. I think this will give us enough flexibility, as it should be possible to handle nulls above the level of the primitive serializer. Hopefully we don't have to force them all to check for null just to get null back :) |
Hi there, is there a workaround (custom serializer ?) to actually send null for any types (even primitives?) using builtValue/StandardJsonPlugin ? My case is that I have a
Sending an empty string is not an option, unfortunately. Thanks |
You can tag the serializers declaration
but this is a whole program option, you can't set it per field or per class. Is that enough for your use case? |
Thanks for your reply. I guess you meant Seems to work perfectly, but I only got it to work when I added it in my specific class, so not globally (which is totally OK for me) :
Tried in the file where I link it all together but without success :
Am I missing something ? Thank ;) |
Sorry, my mistake--I never actually used it so I forgot how it applies. On the class serializer it is, then :) glad it helped :) |
There is an OpenApi generator which generates built_value/dio based classes for OpenApi specifications.
OAS 3.0 and also JSON schema spec support the combination of fields being required but nullable - meaning they have are required in the json output but may be
null
. This combination can currently not be achieved with built_value on a field level.I know that there is a (now removed on master) option
@BuiltValueSerializer(serializeNulls: true)
but this only works for all fields of the same type.Is it possible to add a similar option on a per field basis?
or
See OpenAPITools/openapi-generator#5411
The text was updated successfully, but these errors were encountered: