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

Ignore property when value is null on spring cloud datastore #3257

Open
lucasoares opened this issue Sep 25, 2024 · 3 comments
Open

Ignore property when value is null on spring cloud datastore #3257

lucasoares opened this issue Sep 25, 2024 · 3 comments
Labels
priority: p2 type: bug Something isn't working

Comments

@lucasoares
Copy link
Contributor

lucasoares commented Sep 25, 2024

I'm migrating datastore operations from a GAE python application to a Spring Boot application but there is a compatibility issues between them when mapping entities that have repeated integer fields that are non required. Since datastore is a nosql database, these fields are simply omited by the native datastore library used on the python appengine. But with spring cloud datastore, these properties are saved as a NULL field inside datastore instead.

Example:

Current python example

class Example:
	writers_ids = ndb.IntegerProperty(repeated=True)

Currenty java example

public class Example {
  @Field(name = "writers_ids")
  private List<Long> writersIds;
}

When I save this class to the datastore, if writers_ids are non defined (None in this case), the entity will be saved without the field.

But when I have this same class mapped on spring boot and save it, the property will be saved as a NULL field:
image

In the previous picture, the second line was saved by the python code, and the first, by the java code.

image

When the python application tries to read this entity, it will throw an error "initial generator _put_tasklet(context.py:372) raised BadValueError(Expected integer, got None)" because the porperty exists but is None.

How to omit null fields from being persisted in the datastore?

@burkedavison
Copy link
Member

@cindy-peng : Does Datastore have an opinion on preferred behavior here?

@burkedavison burkedavison added type: bug Something isn't working priority: p2 labels Sep 26, 2024
@mieseprem
Copy link

Hopefully my comment is not just noise: Is Jackson used for (de-)serialisation of objects?
If so, is @JsonInclude(Include.NON_NULL) an option?

@lucasoares
Copy link
Contributor Author

Hopefully my comment is not just noise: Is Jackson used for (de-)serialisation of objects? If so, is @JsonInclude(Include.NON_NULL) an option?

Nope, it does not use jackson. I tried this.

I modified my code to use basic Entity and datastore template directly so when I fetch the object and save it, only existing properties are saved. But this is just a ugly workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants