EventStore / EventStoreDB-Client-Java

Official Asynchronous Java 8+ Client Library for EventStoreDB 20.6+
https://eventstore.com
Apache License 2.0
61 stars 19 forks source link

Support Dependency-Injection of JsonMapper in EventDataBuilder or EventData #256

Closed OliverJurkschat closed 5 months ago

OliverJurkschat commented 7 months ago

It would be really helpful to be able to inject the JsonMapper that is used in EventData.builderAsJson(xx).build(). Especially in SpringBoot-Contexts JsonMapper is often configured and customized in code and supplied as Bean in ApplicationContext. As far as I can tell right now, EventData.builderAsJson()-Operations always create a fresh JsonMapper on every call with no way of outside-interference.

Concrete Usecase: Register the JavaTimeModule.

If i missed something, just dismiss this issue but a pointer on how to achieve something similar would be very helpful.

DEV-216

YoEight commented 7 months ago

Hey @OliverJurkschat,

Something is missing indeed but from our side, an oversight to be precise. We deprecated relying on JsonMapper on any public API, like the EventDataBuilder you mentioned.

The appropriate method is available if you look at EventDataBuilder class directly: https://eventstore.github.io/EventStoreDB-Client-Java/com/eventstore/dbclient/EventDataBuilder.html#json(java.lang.String,byte%5B%5D)

With this method, because you can provide the raw bytes yourself, you can use what ever you like to build your JSON. We forgot to expose that method in the EventData class.

Hiyatei commented 7 months ago

Hey @OliverJurkschat, sorry for the tag on a closed issue.

I'm the Head of Community at Event Store and I'd love to hear more about what you're doing with ESDB and especially how the Java client is working for you. Absolutely no pressure, but if you're interested shoot me an email (alex.rowell@eventstore.com). I'll make sure your feedback gets to the right folks on the team, and happy to help any way I can from the implementation side.

josephcummings commented 5 months ago

For posterity/anyone that may come across this issue, there is a basic Spring Boot Sample that demonstrates how to serialise your event data and pass to the builder as bytes.

The sample uses Gson (registered as a Bean) rather than JsonMapper but the approach would be similar regardless of the mapper used in the application.