小编Mr *_*r K的帖子

如何在java spring-boot上将xml转换为对象

您好,我正在尝试使用对象数量转换 xml,但收到一条错误消息:根元素后面的文档中的标记必须格式正确。

XML:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="test.example.com">
  <Item>
    <ItemKey>1111</ItemKey>
    <Start>2/10/2017</Start>
    <customNumber>12</customNumber>
    <End>2/10/2018</End>
    <Account>2221111</Account>
    <Name>John</Name>
    <Note>GOOD</Note>
    <CodeNo>4444-1</CodeNo>
    <Source>www.cnn.com</Source>
  </Item>
  <Item>
    <ItemKey>2222</ItemKey>
    <Start>2/10/2017</Start>
    <customNumber>75</customNumber>
    <End>2/10/2018</End>
    <Account>3333111</Account>
    <Name>Smith</Name>
    <Note>NOT GOOD</Note>
    <CodeNo>4444-2</CodeNo>
    <Source>www.fox.com</Source>
  </Item>
</string>
Run Code Online (Sandbox Code Playgroud)

型号类别:

package example.models;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Item")
public class Model {

private String CodeNo;

private String ItemKey;

private String Start;

private String End;

private String Account;

private String Name;

private String Note;

...(gets and sets)
Run Code Online (Sandbox Code Playgroud)

主要代码:

StringReader reader = new StringReader(response);
String response = restTemplate.getForObject(url, …
Run Code Online (Sandbox Code Playgroud)

java xml object spring-boot

6
推荐指数
1
解决办法
4万
查看次数

标签 统计

java ×1

object ×1

spring-boot ×1

xml ×1