java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Custom Serialization in Java SDK 1.10 for MongoDB

Open manuraf opened this issue 2 years ago • 2 comments

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"
}

manuraf avatar Oct 28 '23 17:10 manuraf

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.

artursouza avatar Oct 30 '23 23:10 artursouza

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.

xduseko avatar Jan 16 '24 12:01 xduseko