Skip to content

Nested JSON Handling Issue in Generic Class #4669

Open
@MerzoukeMansouri

Description

@MerzoukeMansouri

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions