dapr / java-sdk

Dapr SDK for Java
Apache License 2.0
258 stars 206 forks source link

Custom Serialization in Java SDK 1.10 for MongoDB #942

Open manuraf opened 10 months ago

manuraf commented 10 months ago

Hello,

I'm currently working with Java SDK 1.10 to store a POJO in MongoDB, and I've encountered an issue with the default serialization. When I save the POJO, the result is stored as a string in MongoDB, like this:

value: '{product: "prod", name: "example"}'

I attempted to create a custom serialization using a Jackson object mapper, but unfortunately, the result remains the same:

OBJECT_MAPPER.writeAsByte(pojo)

What I'm aiming for is to have the POJO stored as an object in MongoDB, like this:

value: {
  product: "prod",
  name: "example"
}
artursouza commented 10 months ago

Please, look at the query state example: https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/querystate/README.md

It uses MongoDB and saves the data in a queryable format.

xduseko commented 8 months ago

Same problem here. It seems that DAPR is able to save state as JSON (queryable format) only using HTTP API protocol. It is also used in the demo @artursouza linked.

-Ddapr.api.protocol=HTTP

Unfortunately HTTP API protocol is marked as deprecated in the Java SDK so it's not a very good workaround. It would be nice to have it working with the default gRPC protocol.