【问题标题】:can i pass the xml object with return type of object in web services我可以在 Web 服务中传递具有对象返回类型的 xml 对象吗
【发布时间】:2014-11-19 04:38:34
【问题描述】:

我是 Web 服务开发的新手。我有一个概念。请让我回答。任何一个 Java Web 服务,xml 对象都被设置为参数并带有它们的返回类型。例子

public object find(Object object){
    ...........
    return object;
}

请任何人给我如何做这个概念?高级谢谢...

【问题讨论】:

  • 是的,我们可以通过 pojo 映射实现它

标签: java xml web-services


【解决方案1】:

是的,您可以使用 jaxb marshelling 并将 xml 元素作为对象传递

      public String asString(
                    JAXBContext pContext, 
                    Object pObject)
                        throws 
                            JAXBException {

java.io.StringWriter sw = new StringWriter();

Marshaller marshaller = pContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(pObject, sw);

return sw.toString();
 }

【讨论】:

    猜你喜欢
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多