fix(storage): use JsonUtils for StorageObject serialization in resumable writes and read channels - #13976
Draft
lqiu96 wants to merge 1 commit into
Draft
fix(storage): use JsonUtils for StorageObject serialization in resumable writes and read channels#13976lqiu96 wants to merge 1 commit into
lqiu96 wants to merge 1 commit into
Conversation
…ble writes and read channels When upgrading gRPC to v1.83.0 (and Gson to 2.14.0), Gson PR #3006 added strict duplicate key detection in MapTypeAdapterFactory.Adapter.read ('if (map.containsKey(key)) throw ...'). Because com.google.api.services.storage.model.StorageObject extends com.google.api.client.util.GenericData (which implements java.util.Map), raw Gson selects MapTypeAdapterFactory when serializing and deserializing StorageObject. However, GenericData.containsKey returns true for all @key annotated fields even before they are set, causing raw Gson.fromJson to throw JsonSyntaxException ('duplicate key') when deserializing StorageObject. This replaces raw Gson serialization and deserialization of StorageObject in ApiaryReadRequest and JsonResumableWrite with Google API Client's official JSON parser/serializer via JsonUtils (backed by JsonObjectParser / GsonFactory), resolving the duplicate key deserialization failure in SerializationTest.
Contributor
There was a problem hiding this comment.
Code Review
This pull request replaces direct Gson usage with new helper methods in JsonUtils (objectToJson and jsonToObject) within ApiaryUnbufferedReadableByteChannel and JsonResumableWrite. This centralizes JSON serialization and deserialization using the configured JSON factory. There are no review comments, and I have no additional feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found when upgradeing gRPC to v1.83.0 (as consequently Gson to v2.14.0).
Gson PR #3006 added strict duplicate key detection in MapTypeAdapterFactory.Adapter.read ('if (map.containsKey(key)) throw ...').
Since com.google.api.services.storage.model.StorageObject extends com.google.api.client.util.GenericData (which implements java.util.Map), raw Gson selects MapTypeAdapterFactory when serializing and deserializing StorageObject. However, GenericData.containsKey returns true for all @key annotated fields even before they are set, causing raw Gson.fromJson to throw JsonSyntaxException ('duplicate key') when deserializing StorageObject.
Draft PR to replaces raw Gson serialization and deserialization of StorageObject in ApiaryReadRequest and JsonResumableWrite with Google API Client's official JSON parser/serializer via JsonUtils (backed by JsonObjectParser / GsonFactory), resolving the duplicate key deserialization failure in SerializationTest.