JsonSerializationException when dealing with Json objects in external tasks
See original GitHub issueWhen working with embedded javascript in camunda, it seems that the best way to deal with strings that represent json objects is to convert them with the spin method “S()” and storing them in the format returned by this method, in the camunda rest api this types of objects are returned with a type of “Json” like in the example:
"Item":
{
"type": "Json",
"value": "{"ItemType":0,"Format":"","SourceFormat":9,"SourcePath":"\\\\LOCALHOST\\pathtofile\file.txt","Sample":1,"number":2,"allow":true},"SampleDetails":null}",
"valueInfo":
{
}
}
This representation will result in an exception when trying to pull an external task using the library as it cannot find a type of Json, I believe this is a bug as the library should be able to figure out that the Json type served by camunda is basically a string.
Exception bellow.
System.AggregateException occurred
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at IN.Infrastructure.Workflow.Impl.CamundaWorkflowConsumer.Acquire() in e:\IN\IN.Infrastructure\IN.Infrastructure.Workflow\Impl\CamundaWorkflowConsumer.cs:line 97
InnerException:
HResult=-2146233088
Message=Error converting value "Json" to type 'Camunda.Api.Client.VariableType'. Path '[0].variables.DistributionItem.type', line 1, position 773.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
at Camunda.Api.Client.VariableValue.VariableValueJsonConverter.PopulateMember(String memberName, JsonReader reader, JsonSerializer serializer, Object target)
at Camunda.Api.Client.VariableValue.VariableValueJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Refit.RequestBuilderImplementation.<>c__DisplayClass12_0`1.<<buildCancellableTaskFuncForMethod>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at IN.Infrastructure.Workflow.Impl.CamundaClientContainer.<FetchAndLock>d__d.MoveNext() in e:\IN\IN.Infrastructure\IN.Infrastructure.Workflow\Impl\CamundaClientContainer.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at IN.Infrastructure.Workflow.Impl.CamundaWorkflowConsumer.<AcquireAsync>d__2.MoveNext() in e:\IN\IN.Infrastructure\IN.Infrastructure.Workflow\Impl\CamundaWorkflowConsumer.cs:line 149
InnerException:
HResult=-2147024809
Message=Requested value 'Json' was not found.
Source=mscorlib
StackTrace:
at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
at Newtonsoft.Json.Utilities.EnumUtils.ParseEnumName(String enumText, Boolean isNullable, Type t)
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
InnerException:
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
JSON Error when attempting to consume data from an ...
Inner Exception 1: JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.
Read more >JSON Error when attempting to consume data from an ...
Inner Exception 1: JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.
Read more >JsonSerializationException when changing job state to ' ...
I'm getting an issue with in production using Hangfire 1.4.3. ... JsonSerializationException when changing job state to 'Processing'.
Read more >Exception in JSON Deserialize - Help
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'Newtonsoft.Json.
Read more >Loop over JSON-Array passed by REST
The engine is passed a variable containing JSON including an items-array via external task · The engine should then loop over each of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Merged. You have now option to specify
deserializeValue = false
when reading variables.@jlucansky Here you go https://github.com/jlucansky/Camunda.Api.Client/pull/25
No pressure, take a look whenever you have the time 😃