Repository navigation
Nullable reference fields by default in Java xlang mode for existing POJOs (Jackson/OpenAPI DTOs) #4239
radhakrishnan10192
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Context
We're evaluating Fory xlang (compatible mode) as a binary alternative to JSON for HTTP services. Java servers would write responses that Java, Python and Go clients read. The payload classes are existing DTOs: Jackson POJOs and models generated by OpenAPI Generator / jsonschema2pojo,etc. They're shared across many services and often owned by other teams.
Problem
In xlang mode, Java struct fields are non-nullable by default. Only Optional types and fields whose type carries org.apache.fory.annotation.Nullable can hold null (TypeResolver.isFieldNullable). For DTOs, most fields are optional and routinely null, so serialization fails:
Suggestions:
A builder option such as withXlangNullableFields(true). It would make unannotated non-primitive fields nullable, with Fory's @nullable and @ForyField keeping their explicit meaning.
Recognising well-known Nullable annotations by qualified name with no new dependency. This is similar to what was discussed in #3000 for Nonnull.
How others are handling this situation? this is one of the blocker that i see to adopt fory binary
cc: @chaokunyang
All reactions