Skip to content
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

"Nullable" annotation support #14

Closed
vaind opened this issue Jul 7, 2020 · 2 comments · Fixed by #27
Closed

"Nullable" annotation support #14

vaind opened this issue Jul 7, 2020 · 2 comments · Fixed by #27
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@vaind
Copy link
Contributor

vaind commented Jul 7, 2020

FlatBuffers supports omitting a field - this is evaluated by ObjectBox as if the field had NULL value. Currently, the generated C/C++ code always expects values to be present.

To bring compatibility with other language bindings as well as extend functionality :

  • the FBS schema parser should support a nullable annotation
  • the generated C/C++ code should handle missing values gracefully when reading.
  • open question - what about writing - should we generate pointer-based code (as in Go)? Or go with "default value" (usually zero) as Flatbuffers do?
@vaind vaind added the enhancement New feature or request label Jul 7, 2020
@vaind vaind changed the title Nullable annotation support "Nullable" annotation support Jul 8, 2020
@greenrobot
Copy link
Member

greenrobot commented Jul 8, 2020

What's the current behavior? I think when reading a non-present field from FB e.g. into an int the resulting value should be the the default (zero).

Hmm, nullable... Would like to avoid that (first annotation specific to generator(?)), but I guess we don't have much choice? 🤔 To make things worse, there might be multiple options, e.g. raw pointer, std::unique_ptr and std::optional.

PS.: std::optional represents the FB behavior best. And, if we decide to add an annotation, I see "optional" are a more fitting name.

PSS.: In Java, there are some locations, where you have to provide a "null value". E.g. imagine an annotation on the fbs like "null-value: -1"; reading from FB without a value would result in an int value -1 (and vice versa). I'm not saying that this is the best idea ever, just to throw in some brainstorming here....

@vaind
Copy link
Contributor Author

vaind commented Dec 11, 2020

We could also make use of .fbs field "default" value being explicitly specified to mean the field is nullable and should be stored as null if its value equals to the default... Then the generated store/load code would behave pretty much like standard flatbuffers.

@vaind vaind added this to the 1.0 milestone Dec 11, 2020
@vaind vaind self-assigned this Dec 16, 2020
@vaind vaind mentioned this issue Dec 18, 2020
2 tasks
@vaind vaind closed this as completed in #27 Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants