0

我有一个 Android 客户端和一个 Google App Engine Servlet。
我通过序列化将对象从客户端传输到服务器。
序列化适用于我项目中的所有序列化对象,
除了我保存在我的 JPA 数据库中的名为Profile的实体对象。
现在,当我将 Profile 实例从客户端传输到服务器时,它工作正常
,但是当我从服务器传输到客户端时,我得到如下所示的异常。

我会补充一点,我的代码中没有代码重复。
Profile 类在Server Project 中,Client 项目包含Server 的路径。

W/System.err(1104): java.io.InvalidClassException: javax.jdo.identity.LongIdentity; Incompatible class (SUID): javax.jdo.identity.LongIdentity: static final long serialVersionUID =2472141538875317527L; but expected javax.jdo.identity.LongIdentity: static final long serialVersionUID =2940818939440220368L; 

我的实体类是:

@Entity
public class Profile implements Serializable
{
    private static final long serialVersionUID = 1L;

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private int age;
    private String email;
    private boolean onlineStatus = false;

    public Profile() {}

    public Profile(int age,String email) 
    {
        super();
        this.age = age;
        this.email = email;
    }

    public int getAge() 
    {
        return age;
    }
    public void setAge(int age) 
    {
        this.age = age;
    }

    public String getEmail() 
    {
        return email;
    }

    public void setEmail(String email) 
    {
        this.email = email;
    }

    public boolean isOnlineStatus() 
    {
            return onlineStatus; 
    }

    public void setOnlineStatus(boolean onlineStatus)
    {
        this.onlineStatus = onlineStatus;
    }

完整的堆栈跟踪:

04-21 21:04:56.577: W/System.err(1104): at java.io.ObjectInputStream.verifyAndInit(ObjectInputStream.java:2697)
04-21 21:04:56.577: W/System.err(1104): at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1825)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:811)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2039)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readNewArray(ObjectInputStream.java:1678)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:914)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
04-21 21:04:56.592: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1291)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:518)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1535)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1443)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2112)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readNewArray(ObjectInputStream.java:1678)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:914)
04-21 21:04:56.597: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1291)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:518)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1535)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1443)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2112)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
04-21 21:04:56.607: W/System.err(1104): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
04-21 21:04:56.607: W/System.err(1104): at streetMeet.Client.CustomHttpClient.readObject(CustomHttpClient.java:274)
04-21 21:04:56.607: W/System.err(1104): at streetMeet.Client.CustomHttpClient.executeHttpPost(CustomHttpClient.java:59)
04-21 21:04:56.607: W/System.err(1104): at streetMeet.Client.StreetMeetActivity.connectToServer(StreetMeetActivity.java:154)
04-21 21:04:56.607: W/System.err(1104): at streetMeet.Client.StreetMeetActivity.sendMessageToServer(StreetMeetActivity.java:141)
04-21 21:04:56.607: W/System.err(1104): at map.StreetMapActivity$1.run(StreetMapActivity.java:116)
4

1 回答 1

3

请注意,Java 对象序列化不能保证在不同的 VM 实现之间工作(在这种情况下是 GAE JVM 和 Android Dalvik)。

您应该使用与平台无关的格式进行序列化。最受欢迎的是 JSON。

于 2012-04-22T15:24:16.930 回答