-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If there are HTML tags within XML tags, @JacksonXmlText will assign incorrect values to the content. #623
Comments
version:'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.0' |
Although textual description can be helpful, what would be needed would be full (but ideally minimal) reproduction to show exact problem. |
I have a working example. xml: <Abstract>
<AbstractText><i>Objective</i>. Holographic mixed reality (HMR) allows for the superimposition of computer-generated virtual objects onto the operator's view of the world. Innovative solutions can be developed to enable the use of this technology during surgery. The authors developed and iteratively optimized a pipeline to construct, visualize, and register intraoperative holographic models of patient landmarks during spinal fusion surgery. <i>Methods.</i> The study was carried out in two phases. In phase 1, the custom intraoperative pipeline to generate patient-specific holographic models was developed over 7 patients. In phase 2, registration accuracy was optimized iteratively for 6 patients in a real-time operative setting. <i>Results.</i> In phase 1, an intraoperative pipeline was successfully employed to generate and deploy patient-specific holographic models. In phase 2, the registration error with the native hand-gesture registration was 20.2 ± 10.8 mm (n = 7 test points). Custom controller-based registration significantly reduced the mean registration error to 4.18 ± 2.83 mm (n = 24 test points, <i>P</i> < .01). Accuracy improved over time (B = -.69, <i>P</i> < .0001) with the final patient achieving a registration error of 2.30 ± .58 mm. Across both phases, the average model generation time was 18.0 ± 6.1 minutes (n = 6) for isolated spinal hardware and 33.8 ± 8.6 minutes (n = 6) for spinal anatomy. <i>Conclusions.</i> A custom pipeline is described for the generation of intraoperative 3D holographic models during spine surgery. Registration accuracy dramatically improved with iterative optimization of the pipeline and technique. While significant improvements and advancements need to be made to enable clinical utility, HMR demonstrates significant potential as the next frontier of intraoperative visualization.</AbstractText>
</Abstract> Java: Abstract.java import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import java.util.List;
public class Abstract {
@JacksonXmlElementWrapper(useWrapping = false)
public List<AbstractText> getAbstractText() {
return this.AbstractText;
}
public void setAbstractText(List<AbstractText> AbstractText) {
this.AbstractText = AbstractText;
}
List<AbstractText> AbstractText;
public String getCopyrightInformation() {
return this.CopyrightInformation;
}
public void setCopyrightInformation(String CopyrightInformation) {
this.CopyrightInformation = CopyrightInformation;
}
String CopyrightInformation;
} AbstractText.java package articlemetadata.pubmed.efetch;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonRawValue;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
@JsonIgnoreProperties(value = { "i" , "b", "sup", "sub", "u"})
public class AbstractText {
@JacksonXmlProperty(isAttribute = true)
public String getLabel() {
return this.Label;
}
public void setLabel(String Label) {
this.Label = Label;
}
String Label;
@JacksonXmlProperty(isAttribute = true)
public String getNlmCategory() {
return this.NlmCategory;
}
public void setNlmCategory(String NlmCategory) {
this.NlmCategory = NlmCategory;
}
String NlmCategory;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@JacksonXmlText
@JsonRawValue
String text;
} driver final XmlMapper xmlMapper = XmlMapper.xmlBuilder()
.propertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE)
.build();
String input = " <Abstract>\n" +
" <AbstractText><i>Objective</i>. Holographic mixed reality (HMR) allows for the superimposition of computer-generated virtual objects onto the operator's view of the world. Innovative solutions can be developed to enable the use of this technology during surgery. The authors developed and iteratively optimized a pipeline to construct, visualize, and register intraoperative holographic models of patient landmarks during spinal fusion surgery. <i>Methods.</i> The study was carried out in two phases. In phase 1, the custom intraoperative pipeline to generate patient-specific holographic models was developed over 7 patients. In phase 2, registration accuracy was optimized iteratively for 6 patients in a real-time operative setting. <i>Results.</i> In phase 1, an intraoperative pipeline was successfully employed to generate and deploy patient-specific holographic models. In phase 2, the registration error with the native hand-gesture registration was 20.2 ± 10.8 mm (n = 7 test points). Custom controller-based registration significantly reduced the mean registration error to 4.18 ± 2.83 mm (n = 24 test points, <i>P</i> < .01). Accuracy improved over time (B = -.69, <i>P</i> < .0001) with the final patient achieving a registration error of 2.30 ± .58 mm. Across both phases, the average model generation time was 18.0 ± 6.1 minutes (n = 6) for isolated spinal hardware and 33.8 ± 8.6 minutes (n = 6) for spinal anatomy. <i>Conclusions.</i> A custom pipeline is described for the generation of intraoperative 3D holographic models during spine surgery. Registration accuracy dramatically improved with iterative optimization of the pipeline and technique. While significant improvements and advancements need to be made to enable clinical utility, HMR demonstrates significant potential as the next frontier of intraoperative visualization.</AbstractText>\n" +
" </Abstract>\n";
Abstract abs = xmlMapper.readValue(input, Abstract.class);
String totalAbstract = abs.getAbstractText().get(0).getText();
System.out.println(totalAbstract); This only prints the value of the abstract text AFTER the "Conclusions" italics. Removing the |
This does not seem like valid usage due to a few things:
In general this kind of mixed content is very difficult to make work with data binding.
but you would probably also need to have something like:
|
Thank you for your answer. I am reading this data in from the NCBI pubmed efetch API. I see the problem with why the data binding might not work in this scenario. If it changes in the future I would be happy to know, but for my use case I am using the following (lossy) workaround which I will record here for posterity: HttpResponse<String> fetchResponse = httpClient.send(fetchRequest, HttpResponse.BodyHandlers.ofString());
String body = Optional.ofNullable(fetchResponse.body())
.map(i -> i.replaceAll("<i>", ""))
.map(i -> i.replaceAll("</i>", ""))
.map(i -> i.replaceAll("<b>", ""))
.map(i -> i.replaceAll("</b>", ""))
.map(i -> i.replaceAll("<sup>", ""))
.map(i -> i.replaceAll("</sup>", ""))
.map(i -> i.replaceAll("<sub>", ""))
.map(i -> i.replaceAll("</sub>", ""))
.map(i -> i.replaceAll("<u>", ""))
.map(i -> i.replaceAll("</u>", ""))
.orElse("");
return xmlMapper.readValue(body, clazz); There is perhaps a more elegant way of doing this but it is working for me for now. I hope this helps anyone in the future who stumbles upon this. |
In my ideal world, I would like to be able to specify something like |
But one idea I have had for a while (but no solid plan to implement) has been possibility of something like |
If there are HTML tags within XML tags, the Jackson XML parser will assign incorrect values to the content.
The text was updated successfully, but these errors were encountered: