<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Deserialization of Java Bean not possible within an ivy Script Element</title><link>https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element</link><description>&lt;p&gt;ivy 5.0.9&lt;/p&gt;
&lt;p&gt;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&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;Thanks in advance for your ideas...&lt;/p&gt;
&lt;h2&gt;Helper Class "decode"&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;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;            
    }                       
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Calling the method using Ivy Script Step (Not working)&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;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();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Calling the method directly in the Helper Class by main method (Works great)&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;public static void main(String[] args) {        
    XmlHelper xh = new XmlHelper();     
    Employee employee = new Employee();
    employee = xh.decode("&amp;lt;java version='1.7.0_17' class='java.beans.XMLDecoder'&amp;gt;&amp;lt;object class='test.Employee'&amp;gt;&amp;lt;void property='firstName'&amp;gt;&amp;lt;string&amp;gt;Vorname&amp;lt;/string&amp;gt;&amp;lt;/void&amp;gt;&amp;lt;void property='lastName'&amp;gt;&amp;lt;string&amp;gt;Nachname&amp;lt;/string&amp;gt;&amp;lt;/void&amp;gt;");
    System.out.println(employee.getFirstName());
    System.out.println(employee.getLastName());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;h2&gt;Bean Employee (in ivy located under /src/test/entity )&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;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;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 28 Mar 2014 13:13:01 -0400</lastBuildDate><item><title>Answer by Stefan</title><link>https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element/598</link><description>&lt;p&gt;Hi Peter&lt;/p&gt;
&lt;p&gt;I did the serialization/deserialization with another - free available - library: the simple-xml. With it, it works without any problems and quite fast.&lt;/p&gt;
&lt;p&gt;The library is available at &lt;code&gt;http://simple.sourceforge.net/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Thanks and regards,
Stefan&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stefan</dc:creator><pubDate>Fri, 28 Mar 2014 13:13:01 -0400</pubDate><guid>https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element/598</guid></item><item><title>Comment by Peter Stöckli on Stefan's question</title><link>https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element#567</link><description>&lt;p&gt;Hi Stefan, could you please provide a stacktrace of the ArrayIndexOutOfBoundsException? Also: if you log the in.usrData is the String in the right format or is it somehow escaped?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Peter Stöckli</dc:creator><pubDate>Fri, 07 Mar 2014 12:44:57 -0500</pubDate><guid>https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element#567</guid></item></channel></rss>