[JAVA-4745] Handle recursive types in parameterized records Created: 29/Sep/22  Updated: 28/Oct/23  Resolved: 15/Oct/22

Status: Closed
Project: Java Driver
Component/s: POJO
Affects Version/s: None
Fix Version/s: 4.8.0

Type: Improvement Priority: Unknown
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Gantt Dependency
has to be done before JAVA-4751 Simplify CodecCache Closed
Related
related to JAVA-4740 Support deserialization of records wi... Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Needed

 Description   

The implementation of JAVA-4740 (Support deserialization of records with generic parameters) doesn't handle recursive types, and will result in a runtime recursion that is only halted by a StackOverflowException. We need a different design in order to handle this case properly. An example to make it clearer:

public record RecordTree<T>(T content,
                           @Nullable RecordTree<T> left,
                           @Nullable RecordTree<T> right) {
}

The RecordCodec should be able to handle a record like that, and in general, any sort of cyclical reference. Note that this isn't about actual cycles in the object graph. It's about cycles in the static type definitions.



 Comments   
Comment by Githook User [ 15/Oct/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Support recursive types in parameterized records (#1007)

Provide codec support for records whose type declarations
contain cycles.

JAVA-4745
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/7d73eeec145906663e33502258b60639dc6dec79

Generated at Thu Feb 08 09:02:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.