0

I am having two servers called Server A and B. I am storing one class called person in Server A's session and accessing that person object in server B.

In server A i am having POJO class for person (ie. Serializable and having serialVersionUID) In server B i dont have person class, still I want to deserialize that object value in server B.

deserialize code

ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
try (ObjectInputStream input = new ObjectInputStream(inputStream)) {
    return (Map<String, Object>) input.readObject(); // -> **Exception occur here**
} catch (Exception e) {
    throw Throwables.propagate(e);
}

Can anyone help? Thanks in advance

1 Answers1

0

It's hard to know what you are trying to achieve. You want server B to deserialise an object without knowing what class it is, and Java's deserialization can't do that, furthermore you are trying to cast an unknown class (Person) into a Map.

My suggestion would be to instead use JSON to transmit data between servers. You should be able to easily serialize the Person class into JSON, and deserialize the JSON on Server B into a Map, assuming that the Map is a map of Person fields, and the values are primitive or String.

NickJ
  • 9,380
  • 9
  • 51
  • 74