Summary
Bug in DataClassCodec's getCodec Method with Optional Generic Type Fields
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
5.0
I have encountered a bug within the DataClassCodec implementation of the bson-kotlin library, specifically in the getCodec function. The issue arises when attempting to retrieve type argument information using the typeMap. The bug manifests when a field's type is an optional generic type, leading to a mismatch in the typeMap key.
Upon closer inspection, I found that the existing mechanism for matching the type arguments fails to account for optional generic types adequately, resulting in incorrect or failed codec retrieval. By modifying the matching process to use the type's classifier instead of directly querying the typeMap, the codec resolution process functions correctly, even with optional generic types.
I propose to update the matching logic in the getCodec method to utilize the type's classifier for matching, which has been tested and verified to work as expected. This change addresses the bug by ensuring that type arguments are correctly identified and matched, including those of optional generic types.
I am in the process of finalizing these modifications and will be submitting a pull request (PR) with the proposed changes. I believe this fix will enhance the library's robustness, particularly in handling complex data models that include optional generic types.