How to (de)serialize custom ID object to String? #809
Unanswered
jean-morissette
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
We are using DGS to generate POJO and store/retrieve them directly into Mongo database via DGS graphql web api.
Problem
We want to use Mongo ObjectId as ID in the generated POJO while exposing the ID as a string in the web api.
We should be able to use the method ObjectId.toHexString somewhere to convert ObjectId to String when the POJO is serialized to JSON before sending the response to the client.
Is it possible and if yes, any advices? Thanks in advance.
Example of our code with actual and expected result
GraphQL schema :
build.gradle.kts :
generated types :
actual web endpoint output :
{ "data": { "getFoo": { "id": { "timestamp": 1640673996, "counter": 9263472, "randomValue1": 6782678, "randomValue2": -2695 } } } }desired web endpoint output :
{ "data": { "getFoo": { "id": "61ca579a677ed6f5790f6e2a" } } }Beta Was this translation helpful? Give feedback.
All reactions