GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
423 stars 315 forks source link

Attribute converter like functionality for spring-cloud-gcp-data-datastore #438

Open nbali opened 3 years ago

nbali commented 3 years ago

Is your feature request related to a problem? Please describe. I'm unable to do custom conversions of specific fields between the pojo and db state, because this widely available feature is missing from spring-cloud-gcp-data-datastore, 2.0.2

Describe the solution you'd like https://www.baeldung.com/jpa-attribute-converters#using-the-converter for spring-cloud-gcp-data-datastore :)

Describe alternatives you've considered Without spring data support, I'm forced to use https://github.com/objectify/objectify/blob/master/src/main/java/com/googlecode/objectify/annotation/Translate.java.

Additional context The goal isn't to have a global converter that converts between type A and type B (I think that is already available), but to have an annotation that can control this at the field level OR a global converter that receives the Field object it's converting - so for example it can check for any kind of custom annotation being present. (For example creating a @Sensitive annotation that triggers an encryption during the conversion. https://aws.amazon.com/blogs/developer/client-side-encryption-for-amazon-dynamodb/ does something like this with @DoNotEncrypt).

meltsufin commented 3 years ago

You're right about only global converters being currently supported as described here. If that doesn't work for you, something like JPA's @Convert would need to be added. Unfortunately, I don't think there is such a facility in Spring Data Commons (cc/ @mp911de). As always, we welcome contributions.

mp911de commented 3 years ago

Right now, there's no infrastructure for property-specific converters. Neo4j and Elasticsearch went forward to introduce their store-specific mechanisms. We have a ticket in Spring Data Commons (https://github.com/spring-projects/spring-data-commons/issues/1484) to design and come up with some infrastructure.

nbali commented 3 years ago

Well this tells me the "issue" is real, but just not painful enough for anybody, so everybody is doing a workaround instead. The issue was opened 4 years ago, and barely any interaction on it. Anyway I always thought it's strange it was missing from spring-data and this was usually the reason we went with JPA instead - when we could. My guess is JPA was a too easy and quick alternative for others as well. Not an option with datastore. Unfortunately my knowledge is far from deep enough to contribute code to such a huge feature - even so that I guess there is a reason Neo4j and Elasticsearch did the specific version as well, and not the general one.

So what is the expected flow here? Let the issue be dependent on that one, or should it be closed?

mp911de commented 3 years ago

We don't have a final design for the API and since we expect some changes in the actual store module I'd suggest keeping this ticket open.

zhumin8 commented 2 years ago

update: Spring Data Common has added "support for property-specific converters" in 3.0.0-M2