-
Notifications
You must be signed in to change notification settings - Fork 0
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
[JSON Serialization]Support Default Value #2
Conversation
@@ -198,7 +198,7 @@ class MessageFieldGenerator: FieldGeneratorBase, FieldGenerator { | |||
|
|||
let conditional: String | |||
if isRepeated { // Also covers maps | |||
conditional = "!\(varName).isEmpty" | |||
conditional = "!\(varName).isEmpty || visitor.shouldIncludeDefault()" | |||
} else if hasFieldPresence { | |||
conditional = "let v = \(storedProperty)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure whether we need to handle this. Looks like in proto3, only submessage uses it. Most of fields in proto2 using it. If we also want to get nil in JsonFormat, we can add another method call visitNull(fieldNumber: Int) throws
into Visitor Protocol. So on the codegen side, it will become
if let v = _storage._message {
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
} else if visitor.shouldIncludeDefault {
try visitor.visitingNull(fieldNumber: 1)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the other languages, do they really generate an empty list in json, that seems odd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verified on python, it will return empty array
apple#861
See discussion in the ticket, this PR adds a new method in Visitor Protocol.