JS Unexpected behavior when serializing/deserializing
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- backend-api-design
Research direction
Reproduce the setPkid/serializeBinary/deserializeBinary sequence shown in the issue. Trace the MyMessage setter and serialization/deserialization entry points to identify where the numeric value becomes an empty string. Done means the expected type handling has a maintainer-approved fix or documented decision.
Written by the indexing model from the issue text.
Description
Hello opening this issue because I've seen an unexpected behavior and want to discuss about it and see what's the best pattern
Given the following message:
message MyMessage {
String pkid = 1;
}
If I set a number field into pkid, I'm able to retrieve it correctly. Once I serialize and then deserialize the message, the value gets coerced as an empty string:
> protoConfig.setPkid(123);
> protoConfig.getPkid();
123
> MyMessage.deserializeBinary((protoConfig.serializeBinary())).getPkid()
""
I wasn't expecting the field to be transformed silently once the message is serialized. What I would expect from order of preference:
- Setting the field with
setPkidto crash (or a warning) because the type is not what was expected - Serialization crashing (or a warning) because the type is not expected
- Coercing the type using
toStringwhich would set it to '123'
I understand suggested behaviors may have performance implications but I'm not sure what's the reason of current behavior because this still forces the user to do type checks before setting fields in a protobuf message when using javascript? IMO silently changing the value of a field when serializing a message is dangerous and I would aim for correctness of data first.
- Dominant language
- JavaScript
- Stars
- 471
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from protocolbuffers/protobuf-javascript
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
protocolbuffers/protobuf-javascript#248 · 1 comment · 13 reactions ·
-
question
Difficulty 3/5 1-2 days Newbie friendliness 45/100
protocolbuffers/protobuf-javascript#222 · 9 comments ·
-
enhancement port-fix triaged
Difficulty 4/5 3-5 days Newbie friendliness 35/100
protocolbuffers/protobuf-javascript#185 · 1 comment ·
-
enhancement port-fix triaged
Difficulty 4/5 3-5 days Newbie friendliness 35/100
protocolbuffers/protobuf-javascript#182 · 3 comments · 1 reaction ·
All issues in protocolbuffers/protobuf-javascript
Similar issues
-
Radix number block generates NaN after switching a negative or decimal number to binary, octal or hexPossibly taken @matthewalberto claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mit-cml/appinventor-sources#4246 · 1 comment ·
Maintainers usually reply within 1 day
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
accessibility good first issue languages
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 2 days
-
bug help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100