Caucho Forums  

This forum is permanently closed because of spam. For free community support, please visit Google Groups:


Go Back   Caucho Forums > Hessian

Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2013, 12:58 PM
Habib Habib is offline
Junior Member
 
Join Date: Oct 2012
Posts: 2
Default Hessian deserializer problem by inherited Fields wihr same name

Class B inheritance class A and both classes have a Field “id”. Hessian deserializer overwrite “id” from class B.

public class A implements java.io.Serializable{

protected long id = 100;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}

}

public class B extends A implements java.io.Serializable {

private long id = 200;

@Override
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}

public long getSuperId() {
return super.getId();
}

}

public class Serializertest
{

/**
* @param args
*/
public static void main(String[] args)
{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

Hessian2Output out = new Hessian2Output(bos);
try
{
out.startMessage();

out.writeInt(1);
B b = new B();
out.writeObject(b);
out.close();

byte[] data = bos.toByteArray();
ByteArrayInputStream bin = new ByteArrayInputStream(data);
Hessian2Input in = new Hessian2Input(bin);
in.startMessage();
ArrayList list = new ArrayList();
int length = in.readInt();

for (int i = 0; i < length; i++)
{
list.add(in.readObject());
}

in.completeMessage();
in.close();
bin.close();

b = (B) list.get(0);
System.out.println("id from class B =" + b.getId());
System.out.println("id from class A =" + b.getSuperId());
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

---- Output---
id from class B =100
id from class A =0
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:21 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.