Skip to content

Add option to make message type fields always nullable #9

@mscheong01

Description

@mscheong01

In proto3, message type fields are always optional; adding the optional keyword does not change the compiled java code
i.e)

message Message {
    Field field = 1;
}
message Field {
    string name = 1;
}

is equal to

message Message {
    optional Field field = 1;
}
message Field {
    string name = 1;
}

However, krotoDC currently generates different code for these two cases

data class Message(
    val field: Field = Field()
)
data class Message(
    val field: Field? = null
)

Because of this, when a krotoDC message type field is not set, while message type fields with the optional keyword are "unset", fields without the keyword is set with an empty message (with all fields unset).
Strictly speaking, this contradicts the proto3 syntax's basic rule; that all message fields are optional. But it is true that this difference could be preferred for certain cases.
The best way to go would be adding an option for the krotoDC protoc plugin that when enabled, creates all message type fields as nullable. then, if this is preferred by the majority of users, we could adpot it as the default behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions