使用hashmap将xml转换为java pojo<;字符串,列表<;对象>&燃气轮机;
在下面给出的XML中,我无法将充值类型转换为Hashmap>使用hashmap将xml转换为java pojo<;字符串,列表<;对象>&燃气轮机;,java,xml,spring,jaxb,jackson,Java,Xml,Spring,Jaxb,Jackson,在下面给出的XML中,我无法将充值类型转换为Hashmap> twogdata、fulltalktime、特殊充值是键,其值是MycustomObject的列表。 如果我尝试将此XML转换为JSON,然后再转换为pojo,则没有问题,但我无法直接进行转换。我试过Jackson和JAXB <?xml version="1.0" encoding="UTF-8"?> <rechargeplan> <Response code="200" mess
twogdata、fulltalktime、特殊充值是键,其值是MycustomObject的列表。
如果我尝试将此XML转换为JSON,然后再转换为pojo,则没有问题,但我无法直接进行转换。我试过Jackson和JAXB
<?xml version="1.0" encoding="UTF-8"?>
<rechargeplan>
<Response code="200" message="success" />
<operator name="Airtel" code="ART" />
<circle name="Mumbai" code="ARTMU">
<rechargetype>
<twogdata>
<denomination>301</denomination>
<talktime>0</talktime>
<validity>30 days</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Access to 10 email Ids, unlimited Blackberry Messenger</remarks>
</twogdata>
<twogdata>
<denomination>175</denomination>
<talktime>0</talktime>
<validity>28 days</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>1GB 2G</remarks>
</twogdata>
<fulltalktime>
<denomination>250</denomination>
<talktime>250</talktime>
<validity>unlimited</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Talktime Rs. 250</remarks>
</fulltalktime>
<fulltalktime>
<denomination>300</denomination>
<talktime>300</talktime>
<validity>unlimited</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Talktime Rs. 300</remarks>
</fulltalktime>
<specialrecharge>
<denomination>247</denomination>
<talktime>0</talktime>
<validity>56 days</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Local Airtel mobile calls at 15p/min</remarks>
</specialrecharge>
<specialrecharge>
<denomination>655</denomination>
<talktime>0</talktime>
<validity>45 days</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>2.5 GB 3G</remarks>
</specialrecharge>
<topup>
<denomination>30</denomination>
<talktime>23.2</talktime>
<validity>unlimited</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Talktime Rs. 23.2</remarks>
</topup>
<topup>
<denomination>10</denomination>
<talktime>7.73</talktime>
<validity>unlimited</validity>
<servicetax></servicetax>
<processingfees></processingfees>
<validfrom></validfrom>
<validto></validto>
<remarks>Talktime Rs. 7.73</remarks>
</topup>
</rechargetype>
</circle>
</rechargeplan>
301
0
30天
访问10个电子邮件ID,无限制的Blackberry Messenger
175
0
28天
1GB 2G
250
250
无限的
通话时间250卢比
300
300
无限的
通话时间300卢比
247
0
56天
本地Airtel移动电话,15便士/分钟
655
0
45天
2.5 GB 3G
30
23.2
无限的
通话时间23.2卢比
10
7.73
无限的
通话时间7.73卢比
尝试使用杰克逊
@JacksonXmlRootElement(localName = "rechargeplan")
@Getter
@Setter
public class EnRechargePlan {
@JacksonXmlProperty(localName = "Response")
private Response response;
private Circle circle;
private Operator operator;
@Getter
@Setter
public class Circle {
private String code;
private String name;
private HashMap<String, ArrayList<EnRechargeType>> rechargetype;
@Getter
@Setter
public class EnRechargeType {
private String denomination;
private String talktime;
private String validity;
@JacksonXmlProperty(localName = "servicetax")
private String serviceTax;
@JacksonXmlProperty(localName = "processingfees")
private String processingFees;
@JacksonXmlProperty(localName = "validfrom")
private String validFrom;
@JacksonXmlProperty(localName = "validto")
private String validTo;
private String remarks;
public EnRechargeType(String denomination, String talktime, String validity, String serviceTax, String processingFees, String validFrom, String validTo, String remarks) {
this.denomination = denomination;
this.talktime = talktime;
this.validity = validity;
this.serviceTax = serviceTax;
this.processingFees = processingFees;
this.validFrom = validFrom;
this.validTo = validTo;
this.remarks = remarks;
}
}
}
@Getter
@Setter
public static class Response {
private String message;
private String code;
}
@Getter
@Setter
private static class Operator {
private String code;
private String name;
}
}
@JacksonXmlRootElement(localName=“rechargeplan”)
@吸气剂
@塞特
公共类EnRechargePlan{
@JacksonXmlProperty(localName=“Response”)
私人回应;
私人圈子;
私人经营者;
@吸气剂
@塞特
公共阶级圈子{
私有字符串码;
私有字符串名称;
私有哈希映射类型;
@吸气剂
@塞特
公共类EnRechargeType{
私人字符串命名;
专用字符串通话时间;
私有字符串有效性;
@JacksonXmlProperty(localName=“servicetax”)
个人所得税;
@JacksonXmlProperty(localName=“processingfees”)
私人字符串处理费;
@JacksonXmlProperty(localName=“validfrom”)
私有字符串有效来自;
@JacksonXmlProperty(localName=“validto”)
私有字符串validTo;
私人字符串注释;
public EnrecChargeType(字符串名称、字符串通话时间、字符串有效性、字符串服务税、字符串处理费、字符串有效期自、字符串有效期至、字符串备注){
这个。面额=面额;
this.talktime=通话时间;
有效性=有效性;
this.serviceTax=serviceTax;
这是。处理费=处理费;
this.validFrom=validFrom;
this.validTo=validTo;
这个。备注=备注;
}
}
}
@吸气剂
@塞特
公共静态类响应{
私有字符串消息;
私有字符串码;
}
@吸气剂
@塞特
私有静态类运算符{
私有字符串码;
私有字符串名称;
}
}
使用JAXB
@XmlRootElement(name = "rechargeplan")
public class EuroNetRechargePlan {
// @JacksonXmlProperty(localName = "Response")
private Response response;
private Circle circle;
private Operator operator;
@XmlElement(name = "Response")
public Response getResponse() {
return response;
}
public Circle getCircle() {
return circle;
}
public void setCircle(Circle circle) {
this.circle = circle;
}
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public void setResponse(Response response) {
this.response = response;
}
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public static class Circle {
@XmlAttribute(name = "code")
private String code;
@XmlAttribute(name = "name")
private String name;
@XmlJavaTypeAdapter(Adapter.class)
@XmlElement(name = "rechargetype")
private HashMap<String, ArrayList<EuroNetRechargeType>> rechargeType;
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public static class EuroNetRechargeType {
private String key;
private String denomination;
private String talktime;
private String validity;
@JacksonXmlProperty(localName = "servicetax")
private String serviceTax;
@JacksonXmlProperty(localName = "processingfees")
private String processingFees;
@JacksonXmlProperty(localName = "validfrom")
private String validFrom;
@JacksonXmlProperty(localName = "validto")
private String validTo;
private String remarks;
public EuroNetRechargeType(String denomination, String talktime, String validity, String serviceTax, String processingFees, String validFrom, String validTo, String remarks) {
this.denomination = denomination;
this.talktime = talktime;
this.validity = validity;
this.serviceTax = serviceTax;
this.processingFees = processingFees;
this.validFrom = validFrom;
this.validTo = validTo;
this.remarks = remarks;
}
}
}
@Data
@XmlAccessorType(XmlAccessType.FIELD)
private static class Operator {
@XmlAttribute(name = "code")
private String code;
@XmlAttribute(name = "name")
private String name;
}
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public static class Response {
@XmlAttribute(name = "message")
private String message;
@XmlAttribute(name = "code")
private String code;
}
}
@XmlRootElement(name=“rechargeplan”)
公共类欧洲网络计划{
//@JacksonXmlProperty(localName=“Response”)
私人回应;
私人圈子;
私人经营者;
@xmlement(name=“Response”)
公共响应getResponse(){
返回响应;
}
公众圈{
返回圈;
}
公共无效设置圆(圆){
这个圆=圆;
}
公共运算符getOperator(){
返回运算符;
}
公共无效设置运算符(运算符){
this.operator=操作员;
}
公共无效设置响应(响应){
这个。反应=反应;
}
@资料
@XmlAccessorType(XmlAccessType.FIELD)
公共静态类圈{
@XmlAttribute(name=“code”)
私有字符串码;
@XmlAttribute(name=“name”)
私有字符串名称;
@XmlJavaTypeAdapter(Adapter.class)
@XmlElement(name=“rechargetype”)
私有哈希映射类型;
@资料
@XmlAccessorType(XmlAccessType.FIELD)
公共静态类EuronetType{
私钥;
私人字符串命名;
专用字符串通话时间;
私有字符串有效性;
@JacksonXmlProperty(localName=“servicetax”)
个人所得税;
@JacksonXmlProperty(localName=“processingfees”)
私人字符串处理费;
@JacksonXmlProperty(localName=“validfrom”)
私有字符串有效来自;
@JacksonXmlProperty(localName=“validto”)
私有字符串validTo;
私人字符串注释;
公众的