Can I register databind-jsr310 module when using vertx-web and openapi?

20 views
Skip to first unread message

Santiago Acosta

unread,
Jun 3, 2022, 11:14:09 AMJun 3
to vert.x
Hi everyone,

Vertx: 4.2.2
Jackson: 2.12.0

I have been having problems serializing Java8 LocalDateTime to JSON in my router. My API handlers are generated automatically with the open-api tools but the CODEC seems to be hardcoded.

I can see that the Databind CODEC registers a VertX module and that this module understands Java Instant objects.

Is there any way whatsoever for me to register more modules in this mapper?

I can manually change every endpoint call to the hardcoded codec but this will become cumbersome for larger projects. I would prefer, if it were possible, to register the JSR-310 module (or one of my own) into this codec. Is any of this possible? If not, does anybody know if we will be able to do this in a future version?

hantsy bai

unread,
Jun 3, 2022, 12:16:14 PMJun 3
to ve...@googlegroups.com
Check my example: https://github.com/hantsy/vertx-sandbox/blob/master/post-service/src/main/java/com/example/demo/MainVerticle.java#L25-L34
---

Regards,

Hantsy Bai

Self-employed consultant, fullstack developer, agile coach, freelancer/remote worker

GitHub: https://github.com/hantsy

Twitter: https://twitter.com/@hantsy

Medium: https://medium.com/@hantsy


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/54efac66-1770-4e47-9685-470410b8dc9bn%40googlegroups.com.

Gordan Krešić

unread,
Jun 6, 2022, 11:37:15 AMJun 6
to ve...@googlegroups.com
Like Hantsy already said, accessing hardcoded mapper via `DatabindCodec.mapper()` is the only way I found it to be possible, too.

However, this is way too dirty and often results in code duplication. For example, it prevents you from having one, standardized ObjectMapper through whole project (except if you decide to use DatabindCodec.mapper() in whole project, but that would be super-dirty) and forces you tu configure separately one ObjectMapper for non-Vert.x-related components and Vert.x's own DatabindCodec.mapper(). More often then not, someone changes configuration in only one of those, causing hard-to-find bugs.

Allowing some form of setter/initializer for ObjectMapper that Vert.x uses would be much better.

-gkresic.
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com <mailto:vertx+un...@googlegroups.com>.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/54efac66-1770-4e47-9685-470410b8dc9bn%40googlegroups.com <https://groups.google.com/d/msgid/vertx/54efac66-1770-4e47-9685-470410b8dc9bn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Santiago Acosta

unread,
Jun 7, 2022, 7:15:32 AMJun 7
to ve...@googlegroups.com
I thanked Hantsy directly. His recommendation works. Just configure the hardwired DatabindCodec and everything runs smoothly. I don't know why I didn't trip over such a simple workaround.

I usually work with bootstrapping my "singletons" so I was hoping there were some place where I could put my own ObjectMapper for Vertx to use. I agree that managing different mappers is error prone but I am already taking good care of that.

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/f282ea61-5cf7-74ac-4e90-1ff82312ba23%40steatoda.com.


--
Best regards,
Santiago Acosta Arreaza

Intermodal Telematics S.L.

Prisma building, 1st floor, Office 1.5
Fotógrafo José Norberto Rguez. Díaz st., 2
San Cristobal de La Laguna, SC de Tenerife 
38204, Spain


+34 922 31 56 05
www.intermodaltelematics.com
Reply all
Reply to author
Forward
0 new messages