JSON deserialize error

1,816 views
Skip to first unread message

Thuy Le

unread,
Oct 1, 2015, 6:11:05 AM10/1/15
to camunda BPM users
Hi,
I configured camunda engine to serialize object by default.
In my process, I created a class named Department. This class consists of a attribute called employeeList which comprise a list of Employee object.

The data object is serialized to json as following (see in cockpit):

Value Info:
Object type name: com.gtel.hrworks.model.Department
Serialization Data Format: application/json

Value (Serialized): dept
{"department_id":null,"department_name":"Công nghệ thông tin","employeeList":[{"date":"12/08/2015","employee_id":"01432","employee_name":"Ta Tuan Anh","dept_name":"Công nghệ thông tin","come_default":"8:00","leave_default":"17:00","come":"7:14","leave":"0:00","reason":"5","hr_approved":true}]}

However, cockpit cannot deserialize above variable.

I also try with below java code in delegation class:
Department dept  = (Department) execution.getVariableTyped("dept");

and I met this error:
Deserialization Error: 
Cannot deserialize object in variable 'dept': SPIN/JACKSON-JSON-01007 Cannot construct java type from string 'com.gtel.hrworks.model.Department' 

Anyone have similar issue with this? Please kindly advise. 
Thank you in advance

thorben....@camunda.com

unread,
Oct 1, 2015, 7:11:32 AM10/1/15
to camunda-...@googlegroups.com
Hi,

If your class com.gtel.hrworks.model.Department is not in Cockpit's classpath, then Cockpit can't deserialize the JSON String to an instance of that. That's why Cockpit displays the serialized JSON value as well. Is there a specific reason you need to access the deserialized value in Cockpit for?

As for the issue in your delegate, could you please post the entire exception stack trace?

Cheers,
Thorben

Thuy Le

unread,
Oct 1, 2015, 10:22:33 PM10/1/15
to camunda BPM users
Hi Thorben,

In fact, I would like to retrieve a variable we set before, but when we call 

Department dept  = (Department) execution.getVariableTyped("dept");

I got below error message: Deserialization Error: 
Cannot deserialize object in variable 'dept': SPIN/JACKSON-JSON-01007 Cannot construct java type from string 'com.gtel.hrworks.model.Department' 


I found work around for it: override toString() function in all of the model class (Department and Employee). It works well now.
I don't know how this help actually as I don't call it anywhere.

My function:
public String toString() {
     return "EmployeeRecord "
       + "[date=" + date + ", employee_id=" + employee_id 
       + ", employee_name=" + employee_name + ", dept_name=" + dept_name 
       + ", come_default=" + come_default + ", leave_default=" + leave_default 
       + ", come=" + come + ", leave=" + leave 
       + ", reason=" + reason + ", hr_approved=" + hr_approved +
       "]";
   }

Thank you.

thorben....@camunda.com

unread,
Oct 2, 2015, 3:14:14 AM10/2/15
to camunda BPM users
Hi,

This sounds odd. Are you able to provide a failing test case or a simplified process application project that reproduces the error?

Cheers,
Thorben

Thuy Le

unread,
Oct 2, 2015, 3:32:29 AM10/2/15
to camunda BPM users
Hi Thorben,

Please see attached file for my project. Please remember that I set engine to serialize objects using JSON format by default.

Thank you in advance,
Thuy Le
hrworks.2015.09.30.18.45.rar

Thuy Le

unread,
Oct 2, 2015, 3:35:18 AM10/2/15
to camunda BPM users
With this project, I cannot get dept using this code: Department dept  = (Department) execution.getVariableTyped("dept");

thorben....@camunda.com

unread,
Oct 2, 2015, 3:40:21 AM10/2/15
to camunda BPM users
Hi,

Thanks for the code. Which application server do you use?

Cheers,
Thorben

Thuy Le

unread,
Oct 2, 2015, 3:41:14 AM10/2/15
to thorben....@camunda.com, camunda BPM users

Hi,

I am using Tomcat, shared engine.

 

Thank you and best regards,
Thuy Le

--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/AvA0ZYnh_hM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/1b1f64a0-3d7e-49d7-aa69-5ca58a47882b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

 

thorben....@camunda.com

unread,
Oct 2, 2015, 9:12:52 AM10/2/15
to camunda BPM users, thorben....@camunda.com
Hi Thuy Le,

I slightly modified the process (removed the calls to the mailing library) and wasn't able to reproduce the problem. I get the error only in Cockpit when I access the deserialized variable value which is expected behavior. Could it be that you mistook the error you got in Cockpit to originate from the listener?

Cheers,
Thorben

To unsubscribe from this group and all its topics, send an email to camunda-bpm-users+unsubscribe@googlegroups.com.
To post to this group, send email to camunda-bpm-users@googlegroups.com.

Thuy Le

unread,
Oct 6, 2015, 5:47:07 AM10/6/15
to thorben....@camunda.com, camunda BPM users, thorben....@camunda.com

Hi Thorben,

 

It is so strange, I tried again and no problem occurred.

I removed the toString() function in models, no problem found as well.

I don’t know what happened.

 

By the way, in case that I configure the engine to serialize objects using JSON, could you please advise I should use which of following way to retrieve engine variable?

 

Department dept  = (Department) execution.getVariable("dept");

or

ObjectValue typedDept= execution.getVariableTyped("dept");                  

Department dept = (Department) typedDept.getValue();

 

Thank you for supporting.

Thuy Le

To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.

 

 

--

You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/AvA0ZYnh_hM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/1224f8fa-d906-4a59-9b92-d9e3938138d8%40googlegroups.com.

thorben....@camunda.com

unread,
Oct 6, 2015, 5:58:55 AM10/6/15
to camunda BPM users
Hi Thuy Le,

In the case that you want to access the variable as an instance of the Java type "Department", the two APIs are equivalent. In both cases, the JSON object is deserialized to an instance of "Department" when you call the execution#getVariable* method. The typed value API (the second code snippet you posted) provides additional metadata for the variable and allows to fetch a variable without deserializing it (by calling execution.getVariableTyped("dept", false)). See the section in our user guide on the typed value API [1] for more details.

Cheers,
Thorben

[1] https://docs.camunda.org/manual/7.3/guides/user-guide/#process-engine-process-variables-typed-value-api


Thuy Le

unread,
Oct 6, 2015, 6:01:11 AM10/6/15
to thorben....@camunda.com, camunda BPM users

Hi Thorben,

I got your point. Thanks again for your help.

Best regards,
Thuy Le

 

 


From: thorben....@camunda.com
Sent: Tuesday, October 6, 2015 4:58 PM
To: camunda BPM users
Subject: Re: [camunda-bpm-users] Re: JSON deserialize error

 

 

Hi Thuy Le,

--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/AvA0ZYnh_hM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages