【发布时间】:2018-09-01 08:10:31
【问题描述】:
如何使用 JAXB 注释将 JSON(无根元素)映射到 XML? 似乎很常见?有人也经历过吗?我已经搜索过....提前谢谢!!!!
Karaf 版本 2.4.0.redhat-630310 骆驼2.17.0.redhat-630310
尝试先进行身份验证,获取access_token,然后使用access_token获取对系统资源的访问权限。如何使用 JAXB 注释将 JSON(无根元素)映射到 XML?
这是 JSON 响应:
{"access_token":"eyJhbGciOrZXkiLCJ0eXAiOiJKV1QifQ.","token_type": "bearer","refresh_token":"eyJhbGciXkiLCJ0eXAiOiJKV1QifQ.", "expires_in": 86399, "scope": "password.write openid","jti":75dcd85bd1247b4968f8802e54a9cc1"}
我的 POJO 模型类
package com.ge.dig.predix.entities;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Entities {
@XmlElement(name="access_token")
private String access_token;
@XmlElement(name="token_type")
private String token_type;
@XmlElement(name="refresh_token")
private String refresh_token;
@XmlElement(name="expires_in")
private String expires_in;
@XmlElement(name="scope")
private String scope;
@XmlElement(name="jti")
private String jti;
public String getAccessToken() {
return access_token;
}
public void setAccessToken(String access_token) {
this.access_token = access_token;
}
public String getTokenType() {
return token_type;
}
public void setTokenType(String token_type) {
this.token_type = token_type;
...
【问题讨论】:
标签: json xml-parsing jaxb apache-camel pojo