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

Java.Util.Date fields return 0 instead of null #282

Open
markosalazar opened this issue Jun 18, 2024 · 1 comment
Open

Java.Util.Date fields return 0 instead of null #282

markosalazar opened this issue Jun 18, 2024 · 1 comment

Comments

@markosalazar
Copy link

Hello, currently using protostream v5 for a project and seeing that Java.Util.Date fields all return "0" instead of null when no value is present. I do see that proto 3 syntax has specified the following default values:

For strings, the default value is the empty string.
For bytes, the default value is empty bytes.
For bools, the default value is false.
For numeric types, the default value is zero.
For enums, the default value is the first defined enum value, which must be 0.

Is this the expected behavior with a date field? When unmarshalling it returns a value of new Date("0") which returns the following date: 1969-12-31-19:00:00

Would greatly appreciate your feedback, thank you.

@tristantarrant
Copy link
Member

tristantarrant commented Jun 18, 2024

Since Proto 3 has done away with custom default values, fields should be initialized to their "natural" neutral value.
For Java objects, this means invoking the no-arg constructor. However, because we map java.lang.Date to a number, this is 0. The date you see is the Unix epoch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants