All, I'm using Jackson 2.9.5
I'm trying to parse the XML output of the final-stats module of Blazemeter Taurus.
There is an XML element "Group" with children "perc," for percentile. Perc has a "name" child that is unmapped. I believe the "name" child should be ignored because if I remove @JsonIgnorePropertues(ignoreUnknown=true), Jackson blows up because it doesn't recognize "name."
However when deserializing Group, name is not ignored. Instead I'm getting
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
com.mycompany.myproject.Percentile(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('perc/90.0') at [Source: (BufferedInputStream); line: 4, column: 20] (through reference chain: com.mycompany.myproject.Group["perc"]->java.util.ArrayList[0])
"perc/90.0" is the value of the unmapped "name" element.
What's even weirder is that when I try to deserialize only the perc element, it works fine.
This is the XML that fails:
<?xml version='1.0' encoding='UTF-8'?>
<Group label="https://myhost.mycompany.com:8443/login?from=%2F">
<perc value="0.19300" param="90.0">
<name>perc/90.0</name>
</perc>
</Group
This is my deserialization code:
XmlMapper mapper = new XmlMapper();
mapper.registerModule(new JaxbAnnotationModule());
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("taurus/group-small.xml");
Group group = mapper.readValue(in, Group.class);
This XML works:
<perc value="0.19300" param="90.0">
<name>perc/90.0</name>
</perc>
With this deserialization code:
XmlMapper mapper = new XmlMapper();
mapper.registerModule(new JaxbAnnotationModule());
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("taurus/percentile2.xml");
Percentile p = mapper.readValue(in, Percentile.class);
These are my mapping classes:
package com.mycompany.myproject;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement(name="perc")
public class Percentile {
@XmlAttribute(name="value")
private double value;
@XmlAttribute(name="param")
private double name;
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public double getName() {
return name;
}
public void setName(double name) {
this.name = name;
}
}
package com.mycompany.myproject;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement(name="Group")
public class Group {
@XmlAttribute(name="label")
private String label;
@XmlElement(name="perc")
private List<Percentile> responseTimePercentiles;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<Percentile> getResponseTimePercentiles() {
return responseTimePercentiles;
}
public void setResponseTimePercentiles(List<Percentile> responseTimePercentiles) {
this.responseTimePercentiles = responseTimePercentiles;
}
}
Thanks