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

Nested JSON Handling Issue in Generic Class #4669

Open
MerzoukeMansouri opened this issue Mar 20, 2024 · 2 comments
Open

Nested JSON Handling Issue in Generic Class #4669

MerzoukeMansouri opened this issue Mar 20, 2024 · 2 comments
Assignees
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@MerzoukeMansouri
Copy link

MerzoukeMansouri commented Mar 20, 2024

I encountered an issue while working with Spring Data MongoDB latest version, where nested JSON objects within a generic class are not being handled correctly. Specifically, when attempting to interact with nested JSON structures using Spring Data MongoDB repositories, the behavior does not align with expectations.

Here a repository to reproduce.

Potential bug discovered

  1. When attempting to load a complex structure involving generic classes and nested JSON within a Spring Data MongoDB document, the document fails to load correctly. Despite following standard procedures for data retrieval, the loaded document exhibits inconsistencies, particularly regarding the handling of nested JSON structures.
    image

  2. It's observed that the order of attributes in the entity class has a peculiar effect on the loading process. Specifically, the first generic item within the entity seems to be handled correctly, while the subsequent ones are not processed as expected. This behavior is unexpected and indicates a potential issue with the loading mechanism.
    image

  3. Upon inspection, it becomes evident that the first generic class is loaded correctly, whereas the second one fails to be properly processed during the document loading procedure. This inconsistency in handling generic classes within the document poses a significant hurdle, leading to data integrity concerns and unpredictable behavior.

Set to reproduce demo repository

  1. Set up a Spring Boot project with version 3.2.3 of spring-boot-starter-parent.
  2. Define an entity class (MyEntity) with two attributes (attribute1 and attribute2) that are both of the same generic class (MyGenericClass), but with different nested JSON structures.tures.
  3. Define two different structures (Structure1 and Structure2) for the nested JSON within MyGenericClass.
  4. Implement the repository for MyEntity to handle CRUD operations.
  5. Save instances of MyEntity with different data for attribute1 and attribute2 using MyEntityRepository.save().
  6. Attempt to load the saved MyEntity instances from the database using MyEntityRepository.findAll() or other retrieval methods.

Expected Behavior:
The saved MyEntity instances should be retrieved from the database without any errors or data loss. Both attribute1 and attribute2 should contain their respective nested JSON structures (Structure1 and Structure2).

Actual Behavior:
Upon loading the MyEntity instances, potential issues may arise where the nested JSON structures within attribute1 and attribute2 are not correctly parsed or mapped, leading to unexpected behavior or data inconsistency.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 20, 2024
@christophstrobl
Copy link
Member

@MerzoukeMansouri thank you for getting in touch! Would you mind adding a (failing) junit test to the reproducer? Thank you!

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Mar 20, 2024
@christophstrobl christophstrobl self-assigned this Mar 20, 2024
@MerzoukeMansouri
Copy link
Author

MerzoukeMansouri commented Mar 20, 2024

@MerzoukeMansouri thank you for getting in touch! Would you mind adding a (failing) junit test to the reproducer? Thank you!

Here you are, feel free to ask me any improvements.

Thanks.

DemoRepositoryTest.should_load_nested()

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants