Skip to content

fix(storage): use JsonUtils for StorageObject serialization in resumable writes and read channels - #13976

Draft
lqiu96 wants to merge 1 commit into
mainfrom
fix_grpc_storage_error_v4
Draft

fix(storage): use JsonUtils for StorageObject serialization in resumable writes and read channels#13976
lqiu96 wants to merge 1 commit into
mainfrom
fix_grpc_storage_error_v4

Conversation

@lqiu96

@lqiu96 lqiu96 commented Jul 31, 2026

Copy link
Copy Markdown
Member

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.

…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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Successfully merging this pull request may close these issues.

1 participant