gpt4 book ai didi

java - XML解析: MismatchedInputException: Cannot construct instance of `A` (although at least one Creator exists)

转载 作者:行者123 更新时间:2023-12-02 00:37:52 25 4
gpt4 key购买 nike

我正在使用 third-party library解析 list MPD(用于 DASH 视频流),但是在解析过程中,我在将 XML 解析为对象时收到 MismatchedInputException。 list 可以在 this URL 中找到。 (是直播 list )。

显示的错误如下:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `io.lindstrom.mpd.data.descriptor.Scope` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (StringReader); line: 17, column: 5] (through reference chain: io.lindstrom.mpd.data.MPD["ServiceDescription"]->io.lindstrom.mpd.data.descriptor.ServiceDescription["Scope"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) ~[jackson-databind-2.9.0.jar:2.9.0]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1329) ~[jackson-databind-2.9.0.jar:2.9.0]

现在,一些背景信息。

从同一个 list 中,标签“ServiceDescription”看起来像这样(我无法更改它)

  <ServiceDescription id="1">
<Scope
schemeIdUri="urn:dvb:dash:lowlatency:scope:2019" />
<Latency
target="2000"
max="6000"
min="1000" />
<PlaybackRate
max="1.5"
min="0.5" />
</ServiceDescription>

范围代码定义如下:

import javax.xml.bind.annotation.XmlAttribute;

public class Scope {

@XmlAttribute(name = "schemeIdUri")
private String schemeIdUri;

public Scope(String schemeIdUri) {
this.schemeIdUri = schemeIdUri;
}

public String getSchemeIdUri() {
return schemeIdUri;
}

public void setSchemeIdUri(String schemeIdUri) {
this.schemeIdUri = schemeIdUri;
}
}

包含“The Scope”的类定义如下。我将定义它的标记更改为 @XmlElement、@XmlAttribute,它没有给我任何不同的结果:

package io.lindstrom.mpd.data.descriptor;

import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@XmlType(propOrder = {
"id",
"scope",
"any",
"any"
})

public class ServiceDescription {

@XmlAttribute(name = "id")
private String id;

@XmlAttribute(name = "Scope")
private Scope scope;

@XmlAttribute(name = "Latency")
private Latency latency;

@XmlAttribute(name = "PlaybackRate")
private PlaybackRate playbackRate;

public ServiceDescription(String id, Scope scope, Latency latency,
PlaybackRate playbackRate) {
this.id = id;
this.scope = scope;
this.latency = latency;
this.playbackRate = playbackRate;
}

public ServiceDescription() {
this.id = null;
this.scope = null;
this.latency = null;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Scope getScope() {
return scope;
}

public void setScope(Scope scope) {
this.scope = scope;
}

public Latency getLatency() {
return latency;
}

public void setLatency(Latency latency) {
this.latency = latency;
}

public PlaybackRate getPlaybackRate() {
return playbackRate;
}

public void setPlaybackRate(PlaybackRate playbackRate) {
this.playbackRate = playbackRate;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServiceDescription that = (ServiceDescription) o;
return id == that.id &&
scope.equals(that.scope) &&
latency.equals(that.latency) &&
playbackRate.equals(that.playbackRate);
}

@Override
public int hashCode() {
return Objects.hash(id, scope, latency, playbackRate);
}

public final class Builder {

private String id;
private Scope scope;
private Latency latency;
private PlaybackRate playbackRate;

public Builder withId(String id) {
this.id = id;
return this;
}

public Builder withScope(Scope scope) {
this.scope = scope;
return this;
}

public Builder withLatency(Latency latency) {
this.latency = latency;
return this;
}

public Builder withPlaybackRate(PlaybackRate playbackRate) {
this.playbackRate = playbackRate;
return this;
}

public ServiceDescription build() {
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setId(id);
serviceDescription.setScope(scope);
serviceDescription.setLatency(latency);
serviceDescription.setPlaybackRate(playbackRate);
return serviceDescription;
}
}

}

最佳答案

好吧,在some reading之后,并测试不同的方法,修复错误唯一需要的就是为其添加默认构造函数。

这是添加到类范围的文本

  @SuppressWarnings("unused")
public Scope(){
schemeIdUri = null;
}

有了这个,就足以阻止它继续发生。可能它首先创建空对象,然后添加属性。

关于java - XML解析: MismatchedInputException: Cannot construct instance of `A` (although at least one Creator exists),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57961677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com