Deserialization of Java Bean not possible within an ivy Script Element
ivy 5.0.9
I created an Helper Class which should serialize / deserialize a Java Bean with the java.beans.XMLEncoder / XMLDecoder Class.
Serialization works great, but if I want to deserialize the xml string within an Ivy Script Element, I got the following Error: java.lang.ArrayIndexOutOfBoundsException: 0
If I do the deserialization within the Helper Class itself (as described as follows), the deserialization works great. Is there a way to bring it working within the Ivy Script Step?
Thanks in advance for your ideas...
Helper Class "decode"
---------------------
public Employee decode(String xml) {
try {
XMLDecoder decoder = new XMLDecoder(IOUtils.toInputStream(xml, "UTF-8"));
Employee employee = (Employee) decoder.readObject();
decoder.close();
return employee;
} catch (Exception ex) {
Ivy.log().error(ex.getMessage(), xml);
return null;
}
}
Calling the method using Ivy Script Step (Not working)
---------------------------------------------------
import test.XmlHelper;
import test.Employee;
try {
XmlHelper xh = new XmlHelper();
in.employee = xh.decode(in.usrData);
/*
(in.employee is a DataClass Attr. of type Employee
in.usrData is a DataClass Attr. of type String containing the xml String)
*/
} catch (Exception ex) {
in.errmsg = ex.getMessage();
}
Calling the method directly in the Helper Class by main method (Works great)
----------------------------------------------------------------------------
public static void main(String[] args) {
XmlHelper xh = new XmlHelper();
Employee employee = new Employee();
employee = xh.decode("<java version='1.7.0_17' class='java.beans.XMLDecoder'><object class='test.Employee'><void property='firstName'><string>Vorname</string></void><void property='lastName'><string>Nachname</string></void>");
System.out.println(employee.getFirstName());
System.out.println(employee.getLastName());
}
Bean Employee (in ivy located under /src/test/entity )
------------------------------------------
package test.entity;
import java.io.Serializable;
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
private String lastname = "";
private String firstname = "";
public String getLastName() {
return lastname;
}
public void setLastName(String lastname) {
this.lastname = lastname;
}
public String getFirstName() {
return firstname;
}
public void setFirstName(String firstname) {
this.firstname = firstname;
}
}