JAXB类:对REST的重用 [英] JAXB classes: reuse for REST

查看:51
本文介绍了JAXB类:对REST的重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

技术堆栈:Java 1.6,JPA(休眠3),Spring 3,Oracle 11g

Tech Stack: Java 1.6, JPA (Hibernate 3), Spring 3, Oracle 11g

你好

我们当前正在重构代码,以从基于SOAP的Web服务转向REST. 我有很多XSD,它们用于基于SOAP的WS.并且使用这些模式文件生成了大量的JAXB类.

We are currently refactoring our code to move away from SOAP based web-services to REST. I've got loads of XSD, these were used for SOAP based WS. And there are tons of JAXB classes generated using these schema files.

我的问题是,是否可以将相同的JAXB类用于REST(输入和输出)? 我没有使用REST的经验.

My question is can I use the same JAXB classes for REST (in and out) or not. I've no experience with REST.

推荐答案

比您想象的要好.只需获取先前用于SOAP端点的JAXB对象,然后从控制器返回它们即可:

It's better than you might think. Just take your JAXB object that you used previously for SOAP endpoints and return them from controllers:

public @ResponseBody JAXBElement<JaxbResponseType> 
controllerMethod(@RequestPayload JAXBElement<JaxbRequestType> request) {
    //...
}

Spring看到JAXB批注,将自动将它们编组为XML和JSON.这应该是一个很好的起点,更不用说您的REST服务将具有与SOAP类似的结构.

Spring, seeing JAXB annotations, will automatically marshall them to XML and JSON. This should be a good starting point, not to mention your REST services will have similar structure to SOAP.

这篇关于JAXB类:对REST的重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆