Skip to content

Commit 54846c4

Browse files
committed
read feature
1 parent 4021d53 commit 54846c4

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/main/java/tools/jackson/dataformat/xml/XmlMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ public Builder configureForJackson2() {
249249
.disable(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL)
250250
.disable(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE)
251251
.disable(XmlWriteFeature.AUTO_DETECT_XSI_TYPE)
252-
.disable(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS);
252+
.disable(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)
253+
.disable(XmlReadFeature.AUTO_DETECT_XSI_TYPE);
253254
}
254255

255256
/*

src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import tools.jackson.core.io.NumberInput;
2020
import tools.jackson.core.util.ByteArrayBuilder;
2121
import tools.jackson.core.util.JacksonFeatureSet;
22+
import tools.jackson.dataformat.xml.XmlWriteFeature;
2223
import tools.jackson.dataformat.xml.util.CaseInsensitiveNameSet;
2324
import tools.jackson.dataformat.xml.util.StaxUtil;
2425

@@ -283,6 +284,10 @@ public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive
283284
_streamReadContext.setNamesToWrap(namesToWrap);
284285
}
285286

287+
public final boolean isEnabled(XmlReadFeature f) {
288+
return (_formatFeatures & f.getMask()) != 0;
289+
}
290+
286291
/*
287292
/**********************************************************************
288293
/* JsonParser impl, closing etc

src/test/java/tools/jackson/dataformat/xml/XmlMapperTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import org.junit.jupiter.api.Test;
44
import tools.jackson.core.StreamReadFeature;
5+
import tools.jackson.dataformat.xml.deser.FromXmlParser;
56
import tools.jackson.dataformat.xml.ser.ToXmlGenerator;
67

8+
import javax.xml.stream.XMLInputFactory;
79
import javax.xml.stream.XMLOutputFactory;
8-
import javax.xml.stream.XMLStreamWriter;
910

11+
import java.io.ByteArrayInputStream;
1012
import java.io.ByteArrayOutputStream;
13+
import java.nio.charset.StandardCharsets;
1114

1215
import static org.junit.jupiter.api.Assertions.assertFalse;
1316

@@ -36,5 +39,16 @@ public void testBuilderWithJackson2Defaults() throws Exception
3639
final Point p = new Point(1, 2);
3740
mapper.writeValue(gen, p);
3841
}
42+
43+
final byte[] xml = "<root/>".getBytes(StandardCharsets.UTF_8);
44+
XMLInputFactory inputFactory = mapper.tokenStreamFactory().getXMLInputFactory();
45+
try (
46+
ByteArrayInputStream bis = new ByteArrayInputStream(xml);
47+
FromXmlParser parser =
48+
mapper.createParser(
49+
inputFactory.createXMLStreamReader(bis))
50+
) {
51+
assertFalse(parser.isEnabled(XmlReadFeature.AUTO_DETECT_XSI_TYPE));
52+
}
3953
}
4054
}

0 commit comments

Comments
 (0)