Closed SuperWonggeorge closed 4 years ago
problem 1: serialization failed when I try to unserialize go class with inheritance
it will be fixed in the next days at #150
problem2 : lose attribute when I try to unserialize java class with implement
it's difficult to suport directly: hessian don't encode constant which defined in interface. So we don't relealized the implement behavior
For the reason why it works in java, maybe the value of association='NBA'
is set in class-inited
@aliiohs can you give me some suggest
problem 1: serialization failed when I try to unserialize go class with inheritance
it will be fixed in the next days at #150
Good to hear that , do u have any progress now? thx.
problem2 : lose attribute when I try to unserialize java class with implement
it's difficult to suport directly: hessian don't encode constant which defined in interface. So we don't relealized the implement behavior
For the reason why it works in java, maybe the value of
association='NBA'
is set in class-inited@aliiohs can you give me some suggest
So do u have any further solution?cuz this feature suppose to be necessary for us ,thank you
What happened:
1.serialization failed when I try to unserialize go class with inheritance 2.lose attribute when I try to unserialize java class with implement
What you expected to happen:
Serialize between java and go for all type
How to reproduce it (as minimally and precisely as possible): Q1. `package main
import ( "fmt" "github.com/apache/dubbo-go-hessian2" "os" )
type BasketballPlayer struct { Skill string }
type Demo struct { BasketballPlayer //不支持 Team string Name string Number int Description []string Teammate map[string]string }
func (d Demo) JavaClassName() string { return "app.pojo.Demo" }
func main() { file, err := os.OpenFile("F:\serialization\serializedResult", os.O_WRONLY|os.O_CREATE, 0644) if err != nil { panic(err) } defer file.Close()
} ` I was told "panic: failed to encode field: main.BasketballPlayer, {Skill:}: struct type not Support! main.BasketballPlayer[{}] is not a instance of POJO!" when I try to dubug this
Q2. java code: Association.java `package app.pojo;
import java.io.Serializable;
public interface Association { String associationName = "NBA"; } `
BasketballPlayer.java `package app.pojo;
import java.io.Serializable;
public class BasketballPlayer implements Serializable { public static final long serialVersionUID = 1L; private String skill = "jump shot";
} `
Demo.java `package app.pojo;
import java.io.Serializable; import java.util.List; import java.util.Map;
import lombok.Data;
@Data public class Demo extends BasketballPlayer implements Serializable,Association { private static final long serialVersionUID = 1L; public String skill; private String team; private String name; private int number; private List description;
private Map<String, String> teammate;
}
**App.java**
package app;import java.io.ByteArrayOutputStream;
import com.caucho.hessian.io.Hessian2Output; import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
import app.pojo.Demo;
public class App { public static void main(String[] args) { Demo demo = new Demo(); demo.setTeam("Lakers"); demo.setName("kobeBryant"); demo.setNumber(24); List list = new ArrayList(); list.add("81 points"); list.add("5 champions"); demo.setDescription(list); Map map = new HashMap(); map.put("34","O'Neal"); map.put("16", "Gasol"); demo.setTeammate(map); try { byte[] data = App.serialize(demo); FileOutputStream os =new FileOutputStream(new File("F:\serialization\serializedResult")); System.out.println(data.length); os.write(data); os.close(); System.out.println("done"); } catch (Exception e) { e.printStackTrace(); } }
}
`
go code
`package main
import ( "fmt" "github.com/apache/dubbo-go-hessian2" "io/ioutil" "os" )
type Demo struct { Skill string Team string Name string Number int Description []string Teammate map[string] string AssociationName string }
func (d Demo) JavaClassName() string { return "app.pojo.Demo" }
func main() { file, err := os.Open("F:\serialization\serializedResult") if err != nil { panic(err) } defer file.Close()
}`
result:
API server listening at: 127.0.0.1:50036 {jump shot Lakers kobeBryant 24 [81 points 5 champions] map[16:Gasol 34:O'Neal] }
it lose association='NBA' (didn't happen when I try to unserialize with java)
Anything else we need to know?:
Any solution to fix that problem