Skip to content

spring data elasticsearch can't deserialize "single or array" object field #2280

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

Closed
puppylpg opened this issue Aug 25, 2022 · 4 comments · Fixed by #2282
Closed

spring data elasticsearch can't deserialize "single or array" object field #2280

puppylpg opened this issue Aug 25, 2022 · 4 comments · Fixed by #2282
Assignees
Labels
status: worked on a contributor is working on this issue type: bug A general bug

Comments

@puppylpg
Copy link
Contributor

puppylpg commented Aug 25, 2022

The problem is posted here at first time.

Here is the repo i created by spring boot to reproduce it:

  1. start a elasticsearch of version 7.12, maybe with docker - docker run --name es01-test --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" docker.elastic.co/elasticsearch/elasticsearch:7.12.1;
  2. see resources/insert.txt: add 4 docs manually;
  3. just click and run the project(or through maven: mvn clean spring-boot:run);

Errors will be logged into logs/log.

I'll also try to sovle it(if free this weekend, not guaranteed :D)

Thanks for your efforts.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 25, 2022
@sothawo sothawo self-assigned this Aug 26, 2022
@sothawo sothawo added the type: bug A general bug label Aug 26, 2022
@sothawo
Copy link
Collaborator

sothawo commented Aug 26, 2022

Interesting finding while working on this: Your one-hobby case only works because Lombok is providing an all-args constructor. Using a normal POJO it fails.

Glad I removed all that lombok stuff over a year ago

@sothawo sothawo added status: worked on a contributor is working on this issue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 26, 2022
sothawo added a commit that referenced this issue Aug 29, 2022
When reading from Elasticsearch into a property of type Collection<T> (List<T> or Set<T>) the MappingElasticsearchConverter now can read both from the returned JSON:

    an array of T objects - will put the objects in a corresponding collection
    a single T object will put the single object into a corrsponding colletcion

This is implemented and tested for both: entities where the properties have setters and immutable classes that only provide an all-args constructor.

Original Pull Request #2282
Closes #2280
sothawo added a commit that referenced this issue Aug 29, 2022
When reading from Elasticsearch into a property of type Collection<T> (List<T> or Set<T>) the MappingElasticsearchConverter now can read both from the returned JSON:

    an array of T objects - will put the objects in a corresponding collection
    a single T object will put the single object into a corrsponding colletcion

This is implemented and tested for both: entities where the properties have setters and immutable classes that only provide an all-args constructor.

Original Pull Request #2282
Closes #2280

(cherry picked from commit 86634ce)
sothawo added a commit that referenced this issue Aug 29, 2022
When reading from Elasticsearch into a property of type Collection<T> (List<T> or Set<T>) the MappingElasticsearchConverter now can read both from the returned JSON:

    an array of T objects - will put the objects in a corresponding collection
    a single T object will put the single object into a corrsponding colletcion

This is implemented and tested for both: entities where the properties have setters and immutable classes that only provide an all-args constructor.

Original Pull Request #2282
Closes #2280

(cherry picked from commit 86634ce)
(cherry picked from commit 346c5cc)
@sothawo
Copy link
Collaborator

sothawo commented Aug 29, 2022

Implemented in main and backported to 4.4.x and 4.3.x.

@rishiraj88
Copy link

@sothawo , please give me a resource link to read how backporting is implemented.

@sothawo
Copy link
Collaborator

sothawo commented Aug 29, 2022

check the branches 4.4.x and 4.3.x

@sothawo sothawo added this to the 5.0 M6 (2022.0.0) milestone Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: worked on a contributor is working on this issue type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants