Questions Tagged With deserializationhttps://answers.axonivy.com/tags/deserialization/?type=rssquestions tagged <span class="tag">deserialization</span>enThu, 05 Dec 2019 22:19:28 -0500Deserialization of Map with reference valuehttps://answers.axonivy.com/questions/4242/deserialization-of-map-with-reference-value<p>Dear Ivy team, I face an issue when using Map&lt;String, Object&gt;. I have two key, there has the same value, then it serializes like it:</p> <pre><code>{ "additionalData": { "@class": "Class&amp;lt;java.util.HashMap&amp;gt;", "firstKey": { "@class": "Class&amp;lt;objecttype.Assignee&amp;gt;", "@id": "$Ref-1", "displayName": "Hen" }, "secondKey": "$Ref-1" } } </code></pre> <p>And when deserializes I expect it should be:<br> <b>{firstKey=Assignee [displayName=Hen], secondKey=Assignee [displayName=Hen]}</b></p> <p>But it actual:<br> <b>{firstKey=Assignee [displayName=Hen], secondKey=$Ref-1}</b><br> The second key now map with wrong value.</p> <p>Is there any way to overcome this issue? Thanks a lot!</p>Hen TranThu, 05 Dec 2019 22:19:28 -0500https://answers.axonivy.com/questions/4242/deserialization-of-map-with-reference-valuedeserializationbusiness-dataDeserialization of Java Bean not possible within an ivy Script Elementhttps://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-element<p>ivy 5.0.9</p> <p>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</p> <p>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?</p> <p>Thanks in advance for your ideas...</p> <h2>Helper Class "decode"</h2> <pre><code>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; } } </code></pre> <h2>Calling the method using Ivy Script Step (Not working)</h2> <pre><code>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(); } </code></pre> <h2>Calling the method directly in the Helper Class by main method (Works great)</h2> <pre><code>public static void main(String[] args) { XmlHelper xh = new XmlHelper(); Employee employee = new Employee(); employee = xh.decode("&lt;java version='1.7.0_17' class='java.beans.XMLDecoder'&gt;&lt;object class='test.Employee'&gt;&lt;void property='firstName'&gt;&lt;string&gt;Vorname&lt;/string&gt;&lt;/void&gt;&lt;void property='lastName'&gt;&lt;string&gt;Nachname&lt;/string&gt;&lt;/void&gt;"); System.out.println(employee.getFirstName()); System.out.println(employee.getLastName()); </code></pre> <p>}</p> <h2>Bean Employee (in ivy located under /src/test/entity )</h2> <pre><code>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; } </code></pre> <p>}</p>StefanMon, 24 Feb 2014 14:24:39 -0500https://answers.axonivy.com/questions/545/deserialization-of-java-bean-not-possible-within-an-ivy-script-elementdeserializationivyscript