Oh please help! That’s been the 3rd day since I’ve gotten stuck with this problem and I’m getting a little desperate…
-
There’s two classes: Device and SpliceClosure. Device - a parent class, SpliceClosure - a child class.
-
These classes are the same - in Java and in ActionScript 3
-
For some reason the java class Device serializes OK to AS class Device
** -
But the SpliceClosure class does not. Instead an instance of class Object is instantiated and whenever I try to cast to Device. The error is “type coercion error” in Flex
** -
I have other cases of inheritance, and those serialize well, it’s just this one ■■■■ class!
There’s the code for classes and below the output of BlazeDS debug. You can see that serialization looks similar for both Device and SpliceClosure, and the latter still fails. With no obvious errors reported.
---------------------------- JAVA: Device ---------------------------------------
public class Device implements java.io.Serializable {
private static final long serialVersionUID = 87770011L;
protected Integer id;
protected Location location;
protected String code;
protected String manufacturer;
protected String manufacturerTypeCode;
protected String serialNumber;
protected Set<DeviceConnector> connectors = new HashSet<DeviceConnector>(0);
public Device() {
}
public Device(
Location location,
String code,
String manufacturer,
String manufacturerTypeCode,
String serialNumber,
Set<DeviceConnector> connectors
) {
this.location = location;
this.code = code;
this.manufacturer = manufacturer;
this.manufacturerTypeCode = manufacturerTypeCode;
this.serialNumber = serialNumber;
this.connectors = connectors;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Location getLocation() {
return this.location;
}
public void setLocation(Location location) {
this.location = location;
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
public String getManufacturerTypeCode() {
return manufacturerTypeCode;
}
public void setManufacturerTypeCode(String manufacturerTypeCode) {
this.manufacturerTypeCode = manufacturerTypeCode;
}
public Set<DeviceConnector> getConnectors() {
return connectors;
}
public void setConnectors(Set<DeviceConnector> connectors) {
this.connectors = connectors;
}
public String toString(){
StringBuilder r = new StringBuilder("Device[");
r.append(" id=" + id);
r.append(" code=" + code);
r.append("]");
r.append(super.toString());
return r.toString();
}
}
-------------------------- ActionScript 3: Device ------------------------------------
package sit.si.CableTool.data
{
import mx.collections.ArrayCollection;
import net.digitalprimates.persistence.hibernate.HibernateBean;
[RemoteClass(alias="sit.si.data.CableTool.Device")]
[Managed]
public class Device extends HibernateBean
{
public var id : Number;
public var location : Location;
public var code : String;
public var manufacturer : String;
public var manufacturerTypeCode : String;
public var serialNumber : String;
protected var connectors_: ArrayCollection = new ArrayCollection();
public function get connectors() : ArrayCollection {
if( connectors_ == null ){
connectors_ = new ArrayCollection();
}
return connectors_;
}
public function set connectors(connectors_ : ArrayCollection) : void {
this.connectors_ = connectors_;
}
public function getCables() : ArrayCollection {
var cables : ArrayCollection = new ArrayCollection();
for each( var connector : DeviceConnector in connectors ){
// if( ! cables.contains( cableEndpoint.cable ) ){
// cables.addItem( cableEndpoint.cable );
// }
}
return cables;
}
public function toString() : String {
var result : String = "Device[";
result += "Id: " + id;
result += "Code: " + code;
result += "Location: " + location;
result += "Manufacturer: " + manufacturer;
result += "Serial Number: " + serialNumber;
result += "]";
return result;
}
}
}
--------------- JAVA: SpliceClosure -------------------------------
public class SpliceClosure extends Device implements java.io.Serializable
{
private static final long serialVersionUID = 87770009L;
public SpliceClosure() {
super();
}
}
---------------- ActionScript: Splice Closure ----------------------
package sit.si.CableTool.data
{
import mx.collections.ArrayCollection;
[RemoteClass(alias="sit.si.data.CableTool.SpliceClosure")]
[Managed]
public class SpliceClosure extends Device
{
public override function toString() : String{
var result : String = "SpliceClosure[";
result += "Id: " + id;
// result += "Code: " + code;
// result += "Number of splicings: " + splicings.length;
result += "]";
return result;
}
}
}
---------------------BLAZEDS DEBUG OUTPUT -------------------------------------------------------
[BlazeDS]Adapter 'java-object' called 'sit.si.CableTool.DAO.Devices.getDevice(java.util.Arrays$ArrayList (Collection size:1)
* = 5454
)'
[BlazeDS]Result: 'Device[ id=5454 code=SPL1123]sit.si.data.CableTool.SpliceClosure@8d5aad'
[BlazeDS]Serializing AMF/HTTP response
Version: 3
(Message #0 targetURI=/2/onResult, responseURI=)
(Externalizable Object #0 'DSK')
(Typed Object #1 'sit.si.data.CableTool.SpliceClosure')
id = 5454
connectors = (Externalizable Object #2 'flex.messaging.io.ArrayCollection')
(Array #3)
location = null
manufacturer = null
serialNumber = "1624887"
manufacturerTypeCode = "SP16-SERIES-A1"
code = "SPL1123"
1.263924520428E12
(Byte Array #4, Length 16)
(Byte Array #5, Length 16)
(Byte Array #6, Length 16)
..........
[BlazeDS]Adapter 'java-object' called 'sit.si.CableTool.DAO.Devices.getDevice(java.util.Arrays$ArrayList (Collection size:1)
* = 5555
)'
[BlazeDS]Result: 'Device[ id=5555 code=22222]sit.si.data.CableTool.Device@4ef630'
[BlazeDS]Serializing AMF/HTTP response
Version: 3
(Message #0 targetURI=/3/onResult, responseURI=)
(Externalizable Object #0 'DSK')
(Typed Object #1 'sit.si.data.CableTool.Device')
id = 5555
connectors = (Externalizable Object #2 'flex.messaging.io.ArrayCollection')
(Array #3)
location = null
manufacturer = null
serialNumber = "111111"
manufacturerTypeCode = "44"
code = "22222"
1.263924520646E12
(Byte Array #4, Length 16)
(Byte Array #5, Length 16)
(Byte Array #6, Length 16)