如何解决spring boot中如何序列化和反序列化XML?
我有一个 XML 请求和媒体类型 TEXT/XML 的响应。
我正在尝试在 Spring Boot 中序列化和反序列化请求和响应。
请求正文如下。
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://ws">
<soapenv:Header />
<soapenv:Body>
<ws:doKF>
<parameterIn><![CDATA[<KFWS>
<RqUID>0f73a59f-8388-492e-b17d-ba1fb1b1d2fd</RqUID>
<ClientApp>A</ClientApp>
<SignOn>
<Username>web</Username>
<Password>Web@123</Password>
</SignOn>
<CaListOfflineRq>
<CR>123456</CR>
</CaListOfflineRq>
</KFWS>]]></parameterIn>
</ws:doKF>
</soapenv:Body>
</soapenv:Envelope>
响应如下
<?xml version="1.0" encoding="UTF-8"?>
<NS1:Envelope xmlns:NS1="http://schemas.xmlsoap.org/soap/envelope/">
<NS1:Body>
<NS2:doKFResponse xmlns:NS2="http://ws">
<NS2:parameterOut>
<KFWS>
<RqUID>0f73a59f-8388-492e-b17d-ba1fb1b1d2fd</RqUID>
<LogID>48151382-77bc-11eb-8dbc-0a05010a0000</LogID>
<Status>
<StatusCode>0</StatusCode>
<StatusDesc>Success</StatusDesc>
</Status>
<CaListOfflineRs>
<ReturnCode>0</ReturnCode>
<ReturnDesc>Success</ReturnDesc>
<CaCards>
<CaCard>
<CaMasked>490061</CaMasked>
<CaNoToken>2140</CaNoToken>
<CaToken>2140</CaToken>
<Name>xxxxxxxxxxxxxxx</Name>
<Type>Primary</Type>
<Class>SMART</Class>
<Status>Expired</Status>
<Number>20000</Number>
</CaCard>
<CaCard>
<CaMasked>4904061</CaMasked>
<CaNoToken>2140</CaNoToken>
<CaToken>2140</CaToken>
<Name>xxxxxxxxxxxxxxx</Name>
<Type>Primary</Type>
<Class>SMART</Class>
<Status>Expired</Status>
<Number>20000</Number>
</CaCard>
</CaCards>
</CaListOfflineRs>
</KFWS>
</NS2:parameterOut>
</NS2:doKFResponse>
</NS1:Body>
</NS1:Envelope>
我在字符串中使用 Feign 客户端获得了响应,我需要将响应反序列化为 JSON
解决方法
看起来像是 SOAP 响应。
请参阅显示如何使用此类服务的 Spring tutorial。
,您可以使用 Jackson 来序列化和反序列化您的 xml。您需要查看您的 xml 结构并创建正确的 POJO。在这里您可以找到如何进行序列化/反序列化 https://www.baeldung.com/jackson-xml-serialization-and-deserialization
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。