我正在从zookeeper读取序列化对象的UI上进行反序列化,然后将其转换为JSON。出于某种原因,我无法取消对MQTopic对象的解除关联。但是我能够对其他对象做同样的事情。readObject()之后的代码不运行
这是将byte []转换为MQTopic对象的部分。
if (tester != null && tester.contains("com.ibm.mq.jms.MQTopic")) {
System.out.println(getValue());
ByteArrayInputStream in = new ByteArrayInputStream(this.value);
ObjectInputStream is = new ObjectInputStream(in);
System.out.println("after deserializing..");
topic = (MQTopic) is.readObject();
System.out.println("after typecasting..");
System.out.println(topic.getTopicName());
System.out.println(topic.toString());
is.close();
in.close();
}
这里值是序列化后的对象的字节数组。 topic = (MQTopic) is.readObject();
后什么也没有运行。甚至没有打印报表。程序既不终止,也不会引发或捕获异常。
编辑:全法
public String getStrValue() {
FtpConnectionInfo ftp = null;
MQTopic topic = null;
try {
String tester = new String(this.value, "UTF-8");
if (tester != null && tester.contains("FtpConnectionInfo")) {
ByteArrayInputStream in = new ByteArrayInputStream(this.value);
ObjectInputStream is = new ObjectInputStream(in);
ftp = (FtpConnectionInfo) is.readObject();
in.close();
is.close();
Gson gson = new Gson();
return gson.toJson(ftp);
} else if (tester != null
&& tester.contains("com.ibm.mq.jms.MQTopic")) {
ByteArrayInputStream in = new ByteArrayInputStream(this.value);
ObjectInputStream is = new ObjectInputStream(in);
System.out.println("after deserializing..");
topic = (MQTopic) is.readObject();
System.out.println("after typecasting..");
System.out.println(topic.getTopicName());
System.out.println(topic.toString());
is.close();
in.close();
} else {
return new String(this.value, "UTF-8");
}
} catch (UnsupportedEncodingException ex) {
System.out.println("unsupported error ");
ex.printStackTrace();
//logger.error(Arrays.toString(ex.getStackTrace()));
} catch (Exception e) {
System.out.println("Exception in new logic.");
e.printStackTrace();
}
System.out.println("im out of try");
return null;
}
的FTP,如果环路正常工作,但主题循环不超过类型转换工作。
编辑2:这给其他球队存储对象到动物园管理员
public static byte[] serialize(Object obj) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(out);
os.writeObject(obj);
return out.toByteArray();
}
字节[]存储在动物园管理员,这就是我在我的UI我检索。
编辑3:我做了一个调试进程,并在被调用的地方,这些是值。任何人都可以告诉我,如果对象是正确的?
您的代码中是否启用了记录器?根据您的评论,可能在读取对象时出现异常。 – Arvind
*有*是该线上的异常。 JVM不会随机停止执行代码。您是否尝试过使用调试器来查看实际发生的事情? – Raniz
你的意思是试试看?我不明白记者的意思。 – v1shnu