[JAVA-4832] Default CodecRegistry isn't able to handle custom implementation of Number Created: 23/Dec/22 Updated: 27/Oct/23 Resolved: 16/Jan/23 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Codecs |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | ich mag | Assignee: | Jeffrey Yemin |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryI am trying to load a JsonObject (part of the GSON library) that includes numbers. Gson outputs the numbers with the type "com.google.gson.internal.LazilyParsedNumber". Basically a class that extends Java's general Number class, that stores the loaded number as a String and parses it when needed. Now I am trying to execute an update with Gson's Number, however this leads to an error:
_[23:52:26 WARN]: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for CodecCacheKey{clazz=class com.google.gson.internal.LazilyParsedNumber, types=null}.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).Sync 4.8.1. Doesn't seem to be present with the latest (3.12.11) normal driver. How to Reproduce
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by PM Bot [ 16/Jan/23 ] | ||||||
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. | ||||||
| Comment by Jeffrey Yemin [ 31/Dec/22 ] | ||||||
|
This is by design, as your hot fix demonstrates that some logic is required to properly serialize instances of this class. If you want to handle this more seamlessly, the best way to is to create an implementation of Codec< LazilyParsedNumber> and register is with the MongoClient instance used by the application. See here for documentation on how to do that. | ||||||
| Comment by ich mag [ 23/Dec/22 ] | ||||||
|
That's the hotfix that I am using
Not a decent solution |