[JAVA-4584] Validate map types Created: 21/Apr/22  Updated: 24/Jul/23

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

Type: Improvement Priority: Unknown
Reporter: Ross Lawley Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Investigate our POJO implementation
Quarter: FY23Q4, FY24Q2

 Description   

Validate Map types to ensure when writing to the Pojo or to MongoDB they are of type Map<String, ?>. Check any concrete Map implementations eg:

 Type[] genericInterfaces = Document.class.getGenericInterfaces();
        for (var type : genericInterfaces) {
            if (type instanceof ParameterizedType parameterizedType) {
                System.out.println(parameterizedType.getRawType().getTypeName());
                for (var typeArguments : parameterizedType.getActualTypeArguments()) {
                    System.out.println("   " + typeArguments.getTypeName());
                }
            }
        }
prints:
 
java.util.Map
   java.lang.String
   java.lang.Object



 Comments   
Comment by Ross Lawley [ 21/Apr/22 ]

Note: JAVA-4426 added an annotation BsonExtraElements which could check the type being used is of Map<String, ?> but perhaps any type should be checked / validated.

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