cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Custom Java Objects in Message Property?

0 Kudos
712

Hi,

I have custom jar that is added to iflow as a resource. In the iflow, in one of the script component we are creating instance of custom java class and then setting custom java object to the message property. Further in iflow I am trying to retrieve the message property to make use of the custom java object that was stored previously. Syntax wise everything looks good, no errors but at runtime it is failing due to below error,

Why is it trying to cast an object of the same type to it's type, and then failing to do so?

It seem below error is related to classloader, can you please help how we can resolve this error.

Your solution will help to make use of custom java objects in CPI to set/get from message property especially when you want to hold complex data structure where using of standard collection objects like Map and List is not sufficient.

Message processing failed.

Processing Time: 77 ms Error Details javax.script.ScriptException: java.lang.Exception: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.custom.test.EmployeeDetails1095C@5f4488f1' with class 'com.custom.test.EmployeeDetails1095C' to class 'com.custom.test.EmployeeDetails1095C'@ line 16 in TestReadCustomJavaObjects.groovy, cause: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.custom.test.EmployeeDetails1095C@5f4488f1' with class 'com.custom.test.EmployeeDetails1095C' to class 'com.custom.test.EmployeeDetails1095C'

Thanks

-Anand R Hungund

View Entire Topic
VijayKonam
Active Contributor
0 Kudos

Did you try the property type to be a Java Object and explicitly convert it with in the script? I am assuming, you must have defined the peroperty type as your custom class. We did use the Property to store java Maps and Lists but never a custom object. I do not know for sure if there is any limitation on the CPI Properties to be able to store other java objects.

0 Kudos

Thanks Vijay for the reply, yes I have used generics in my code.

I have taken care of variable type and returned object type are same. I have added code above to Morten comment, please check. Use of Maps and List work fine for simple data but we are trying to use complex data structure so decide to use custom Java Object instead of using multiple nested maps in the property.