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

Dapr client.saveStore(..) doesn't honour stateSerializer contentType

Open antoniomaria opened this issue 1 year ago • 4 comments

Expected Behavior

After calling client.saveStore(..) with some arbitrary state like in StateClient.java example. I would like that state stored should look like this using MongoDb:

image

Actual Behavior

image

Steps to Reproduce the Problem

Run example StateClient.java using Mongo as statestore.

dapr run --components-path ./components/state --app-id state-example -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.state.StateClient 'my message'

Release Note

RELEASE NOTE: FIX Dapr java SDK client uses default state serializer contentType when saving states. By the default json.

antoniomaria avatar Apr 09 '24 06:04 antoniomaria

My suggestion to solve the problem is to use the defaultStateSerializer contentType when building the StateRequest.

Similarly like if one saves the state using 'saveBulkState' method:

Map<String, String> meta = new HashMap<>();
// Dapr built-in saveState method doesn't define the value contentType, causing to store in MongoDb a String
meta.put("contentType", "application/json");

StateOptions options =
       new StateOptions(StateOptions.Consistency.EVENTUAL, StateOptions.Concurrency.LAST_WRITE);

  SaveStateRequest request =
              new SaveStateRequest(STATE_STORE_NAME).setStates(new State<>(FIRST_KEY_NAME, myClass, "", meta, options));

antoniomaria avatar Apr 09 '24 06:04 antoniomaria

This would be a great opportunity to make this change if you are up opening a PR 🙂 @antoniomaria

cicoyle avatar Apr 09 '24 15:04 cicoyle

I would be delighted to do it, I am just a bit newbie in open source collaboration. If someone assigns the ticket to my self, and can open a PR and.. start the review process.

antoniomaria avatar Apr 10 '24 09:04 antoniomaria

I just opened a PR with my suggestion. It needs some E2E testing, or more junit coverage but I think, explains what I am trying to achieve. https://github.com/dapr/java-sdk/pull/1033

antoniomaria avatar Apr 10 '24 10:04 antoniomaria

@cicoyle could you ask feedback for my https://github.com/dapr/java-sdk/pull/1033 ? it's has been idled for quite a while

antoniomaria avatar Jun 24 '24 06:06 antoniomaria