jackson-all 和 jackson-mapper-asl 的最新 jar 版本是什么?我有 jackson-all-1.9.9.jar 和 jackson-mapper-asl-1.9.13.jar,但我不确定它们是最新的,请告诉我,谢谢
你能帮我解析以下 XML 文件吗?
<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns="http:/foo.com">
<date>2017-10-25T09:13:54+02:00</date>
<element>
<id>1</id>
<name>Stuart</name>
<age>34</age>
<regdate><date>2017-10-25T09:13:54+02:00</date></regdate>
</element>
<element>
<id>2</id>
<name>Lora</name>
<age>12</age>
<regdate><date>2017-10-25T09:13:54+02:00</date></regdate>
</element>
<element>
<id>3</id>
<name>Ben</name>
<age>50</age>
<regdate><date>2017-10-25T09:13:54+02:00</date></regdate>
</element>
</dataset >
Run Code Online (Sandbox Code Playgroud)
我尝试像这样创建 pojo:
@Getter
@Setter
@JacksonXmlRootElement(localName = "element")
public class ElementXML {
@JacksonXmlProperty(localName = "id")
private Long id;
@JacksonXmlProperty(localName = "name")
private String name;
@JacksonXmlProperty(localName = "age")
private Long age;
@JacksonXmlProperty(localName = "regdate")
private LocalDateTime regdate;
}
Run Code Online (Sandbox Code Playgroud)
我使用的解析机制在这里:
XMLInputFactory f = XMLInputFactory.newFactory();
File inputFile = new File("some path");
XMLStreamReader sr = f.createXMLStreamReader(new …
Run Code Online (Sandbox Code Playgroud) 我的 XML 看起来像
<IDSentrieServiceResponse>
<session_id>session_number</session_id>
<service name="IDSentrieUser" version="1.1">
<action id="IPIDActivityGet">
<status>0000</status>
<status_msg>optional msg</status_msg>
<user_activity_list>
<username>john</username>
<user_activity>
<time_start>GMT Time</time_start>
<time_end>GMT Time</time_end>
<user_hostname>John.a10networks.com</user_hostname>
<server_ip>192.168.3.249</server_ip>
<server_hostname>dcsrvr.a10networks.com</server_hostname>
<domain_name>a10.net</domain_name>
<dc_name>dc-server-name</dc_name>
</user_activity>
</user_activity_list>
</action>
</service>
</IDSentrieServiceResponse>
Run Code Online (Sandbox Code Playgroud)
我正在使用fastxml-databind将其放入 Java 对象中。我有一堆 DTO,但无法创建对象的地方是
public class UserActivityList {
@JacksonXmlProperty(localName = "username")
private String userName;
@JacksonXmlElementWrapper(useWrapping=false, localName = "user_activity")
private List<UserActivity> userActivity;
public void setUserActivity(List<UserActivity> userActivity) {
this.userActivity = userActivity;
}
@Override
public String toString() {
return "UserActivityList{" +
"userName='" + userName + '\'' +
", userActivity=" + userActivity …
Run Code Online (Sandbox Code Playgroud) 我编写了一个spring boot应用程序来接受Http get Request并发送XML响应作为输出.我需要通过HTTP获取以下XML作为输出
<response xmlns="">
<userId>235</userId>
<amount>345.0</amount>
</response>
Run Code Online (Sandbox Code Playgroud)
而我的DTO课程如下,
@XmlRootElement(name = "response")
public class CgPayment {
@XmlElement
private String userId;
@XmlElement
private double amount;
@XmlElement
public String getUserId() {
return userId;
}
@XmlElement
public void setUserId(String userId) {
this.userId = userId;
}
@XmlElement
public void setAmount(double amount) {
this.amount = amount;
}
@XmlElement
public double getAmount() {
return amount;
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了以下响应作为输出.
<CgPayment xmlns="">
<userId>235</userId>
<amount>345.0</amount>
</CgPayment>
Run Code Online (Sandbox Code Playgroud)
如何更改根元素.响应类型为APPLICATION_XML_VALUE
我有一个具有相同属性的标签列表,但没有包装元素将其作为数组列表..如何将其作为 Java Spring-boot 应用程序中的数组列表保存?
<Vouch_info>
<Note a="sometext"/>
<Quote b="sometext"/>
<Currency country="US" rate="0.00"/>
<Currency country="UK" rate="1.00"/>
<Currency country="AU" rate="2.00"/>
<Currency country="IN" rate="3.00"/>
<Currency country="EU" rate="4.00"/>
<Currency country="SA" rate="5.00"/>
</Vouch_info>
Run Code Online (Sandbox Code Playgroud) 将对象序列化为 XML 并使用 \n @JacksonXmlRootElement(namespace = "http://...")
\n指定属性的命名空间时,Jackson 会将 \xc2\xb4wstxns1\xc2\xb4 附加或前置到命名空间。例如,假设我们有这些类:
VtexSkuAttributeValues.java
\n\n@JacksonXmlRootElement(localName = "listStockKeepingUnitName")\npublic class VtexSkuAttributeValues {\n\n @JacksonXmlProperty(localName = "StockKeepingUnitFieldNameDTO", namespace = "http://schemas.datacontract.org/2004/07/Vtex.Commerce.WebApps.AdminWcfService.Contracts")\n @JacksonXmlElementWrapper(useWrapping = false)\n private VtexSkuAttributeValue[] stockKeepingUnitFieldNameDTO;\n\n public VtexSkuAttributeValue[] getStockKeepingUnitFieldNameDTO() {\n return stockKeepingUnitFieldNameDTO;\n }\n\n public void setValues(VtexSkuAttributeValue[] values) {\n this.stockKeepingUnitFieldNameDTO = values;\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\nVtexSkuAttributeValue.java
\n\n@JacksonXmlRootElement(localName = "StockKeepingUnitFieldNameDTO", namespace = "http://schemas.datacontract.org/2004/07/Vtex.Commerce.WebApps.AdminWcfService.Contracts")\npublic class VtexSkuAttributeValue {\n\n private String fieldName;\n private FieldValues fieldValues;\n private int idSku;\n\n public int getIdSku() {\n return idSku;\n }\n\n public String getFieldName() {\n …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种使用 kotlin 解析大型 xml 的方法。
我常用的 JSON 解析器是 Jackson,我知道它也可以用来解析 xml。
源文件太大,无法使用 DOM 方法进行解析,我必须使用流 API。我可以找到几个关于如何将 Jackson Streaming API 与 JSON 结合使用的示例,但没有找到关于 XML 的示例。文档https://github.com/FasterXML/jackson-dataformat-xml说
尽管模块实现了低级(JsonFactory / JsonParser / JsonGenerator)抽象,但大多数使用都是通过数据绑定级别。这是因为在数据绑定级别添加了少量解决方法,以解决 XML 特性:
这让我担心这个库的 XML 流方法是否可行和/或支持。
在我的反应式 REST API 中,我试图返回一个XML
响应。但是,我总是得到一个JSON
,即406 NOT_ACCEPTABLE
。知道为什么吗?
@RestController
@RequestMapping(path = "/xml", produces = APPLICATION_XML_VALUE)
public class RestApi {
@GetMapping(path = "/get")
public Publisher<ResponseEntity> get() {
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(new Datta("test")));
}
@PostMapping(path = "/post", consumes = APPLICATION_XML_VALUE)
public Publisher<ResponseEntity<Datta>> post(@RequestBody Datta datus) {
datus.setTitle(datus.getTitle() + "!");
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(datus));
}
}
Run Code Online (Sandbox Code Playgroud)
java.lang.AssertionError: 预期:application/xml 实际:application/json;charset=UTF-8
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id "io.spring.dependency-management" version "1.0.7.RELEASE"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.8"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Run Code Online (Sandbox Code Playgroud)
我必须将大量数据编组为 XML 格式。我正在研究 JAXB,因为它是 JDK 8 的一部分,但我不确定它如何处理大量数据。Jackson XML 是我遇到的另一个更新的库。Jackson 在将对象序列化为 XML 方面是否比 JAXB 更快?