Search code examples
mulemule-componentmulesoftmule4

How to resolve Could not serialize object Caused error while using cache scope in mule 4


I have added caching scope in my flow for response of the http request. before caching scope i have a set-variable component that has the json object becasue of that i'm getting error. when i am removing the set-variable it's working. How can i resolve the issue even i am using set-variable?

Error:

 com.mulesoft.mule.runtime.cache.internal.ObjectStoreCachingStrategy: Unable to store event in cache
 org.mule.runtime.api.store.ObjectStoreException: Could not serialize object Caused by: 
 org.mule.runtime.api.serialization.SerializationException: Could not serialize object 

flow:

<flow name="tokenFlow" doc:id="cb6d9de3-45fa-47f0-b2f5-875048d0b980" ><http:listener doc:name="Listener" doc:id="36c16957-47c1-4d07-b6c2-694e6c86a9f3" config-ref="HTTP_Listener_config" path="/fssvc-api/collectionSFDCInbound"/>
    <set-variable value="#[payload]" doc:name="Set Variable" doc:id="3f372591-b02a-4d82-a634-159b865090ca" variableName="request" />
    <ee:cache doc:name="Cache" doc:id="ae4c75b2-5e92-4578-9966-1277b47b472a" cachingStrategy-ref="Caching_Strategy1">
        <http:request method="POST" doc:name="Request" doc:id="08d40c87-8f60-4b4e-8e20-1c93c1b52477" config-ref="HTTP_Request_configuration" url="https://idfcfirstbank--colqaorg.my.salesforce.com/services/oauth2/token?">
        <http:query-params><![CDATA[#[output
  application/java
   ---
 {
"password" : "test",
"grant_type" : "password",
"client_secret" : "test1234",
"client_id" : "1234",
"username" : "[email protected]"
}]]]></http:query-params>
    </http:request>
    </ee:cache>
</flow>

Solution

  • That problem is described in the KB article https://help.mulesoft.com/s/article/Mule-4-flow-variable-causing-ObjectStoreException

    As it explains, you could convert the variable to a String to avoid the serialization issue.

    Example:

    <set-variable value="#[output application/java --- payload as String]" ...>
    

    Since Mule 4.3.0 the scope of information stored in the cache has been narrowed so migrating the version of Mule to the last one is a solution.