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

Implement datastore Blob to byte[] conversion on read #729

Merged
merged 4 commits into from
Nov 22, 2021

Conversation

elefeint
Copy link
Contributor

@elefeint elefeint commented Nov 19, 2021

Blob-to-byte[] and reverse are a special case in conversion -- it's the only exception to the general rule of "Datastore collection becomes Java collection; Datastore simple type becomes Java type". It seems to have been intended to work in original implementation, but never had a test, so either never worked right or broke over the years. The other direction, on write, works fine through BYTE_ARRAY_TO_BLOB_CONVERTER combined with ValueUtil.isArrayOfItems() exempting byte[] from array status.

There were several ways of fixing this (each commit in this PR is a working solution), but at the end I went with making the standard conversion path worked. It required redefining the meaning of collection to exclude byte arrays, which is already done in the local utility ValueUtil.isArrayOfItems(). I replaced Spring Data's built-in TypeDiscoverer.isCollectionLike(), which (reasonably) assumes byte arrays are collection-like with the Spring Cloud Gcp Datastore implementation-specific ValueUtil.isArrayOfItems(), which excludes byte[]. This exclusion is already documented in the refdoc, so no additional documentation is needed.

Fixes #661.

@sonarcloud
Copy link

sonarcloud bot commented Nov 19, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

I like the simple fix. LGTM.

@elefeint elefeint merged commit 2a705be into main Nov 22, 2021
@elefeint elefeint deleted the datastore_blob_byte_conversion branch November 22, 2021 15:17
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
…tform#729)

Fix the Blob-to-byte-array conversion on Datastore entity read.
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.

[Spring Cloud Datastore] Can't read Blob type into byte[] using Repository and Entity
2 participants