[英]groovy soapUI deserialize
Just started using soapUI and I like it a lot. 刚开始使用soapUI,我非常喜欢它。
In a particular case using REST, I'm receiving serialized object. 在使用REST的特定情况下,我正在接收序列化的对象。
I would like : 我想要 :
to retrieve the serialized byte array and transform it into a Java object 检索序列化的字节数组并将其转换为Java对象
re-transform the java object into an XML response (using JAXB) so it can be human readable. 将Java对象重新转换为XML响应(使用JAXB),以便可以被人类阅读。
Is this feasible? 这可行吗?
Be sure to consider using XML serialization (eg XStream ) instead of binary one to avoid version compatibility problems before using the next solution: 在使用下一个解决方案之前,请务必考虑使用XML序列化(例如XStream )而不是二进制序列化,以避免版本兼容性问题 :
Import your Java class to SoapUI groovy script ( as described there ) or re-define your Java class in Groovy code with Serializable
interface implemented: 将Java类导入到SoapUI groovy脚本( 如此处所述 ),或在已实现
Serializable
接口的Groovy代码中重新定义Java类:
class Person implements Serializable { String name; int age }
Use ObjectInputStream
and classLoader
to load deserialize objects into object: 使用
ObjectInputStream
和classLoader
将反序列化的对象加载到对象中:
// use your byte array variable instead of yourByteArray input = new ByteArrayInputStream(yourByteArray) // use your object variable instead of yourObject yourObject = null input.withObjectInputStream(getClass().classLoader){ ois -> yourObject = ois.readObject() }
Use ObjectOutputStream
to serialize updated objects and save them to an XML response: 使用
ObjectOutputStream
序列化更新的对象并将其保存到XML响应中:
output = new ByteArrayOutputStream() output.withObjectOutputStream { oos -> oos << yourObject } //save serialized data as byte array output.toByteArray()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.