google / google/built_value.dart

Support serializing null on a per field basis - nullable vs required

Open
#912 12 comments 5 reactions 1 assignee Claimed by @davidmorgan View on GitHub
p2 / feature request
Dominant language
Dart
Stars
886
Forks
195
Avg merge
1d 11h
Merged PRs (30d)
4

Description

There is an OpenApi generator which generates built_value/dio based classes for OpenApi specifications.

OAS 3.0 and also [JSON schema spec](http://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5.3) 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?

```
@nullable
@BuiltValueField(serializeNulls: true)
String foo;
```
or
```
@BuiltValueField(serializeNulls: true)
String? foo;
```

See https://github.com/OpenAPITools/openapi-generator/issues/5411

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.