forked from FasterXML/jackson-dataformat-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlMapperTest.java
54 lines (46 loc) · 2.18 KB
/
XmlMapperTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package tools.jackson.dataformat.xml;
import org.junit.jupiter.api.Test;
import tools.jackson.core.StreamReadFeature;
import tools.jackson.dataformat.xml.deser.FromXmlParser;
import tools.jackson.dataformat.xml.ser.ToXmlGenerator;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class XmlMapperTest extends XmlTestUtil
{
@Test
public void testBuilderWithJackson2Defaults() throws Exception
{
XmlMapper mapper = XmlMapper.builderWithJackson2Defaults().build();
assertFalse(mapper.isEnabled(StreamReadFeature.USE_FAST_DOUBLE_PARSER));
assertFalse(mapper.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
XMLOutputFactory outputFactory = mapper.tokenStreamFactory().getXMLOutputFactory();
try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ToXmlGenerator gen =
mapper.createGenerator(
outputFactory.createXMLStreamWriter(bos))
) {
assertFalse(gen.isEnabled(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL));
assertFalse(gen.isEnabled(XmlWriteFeature.UNWRAP_ROOT_OBJECT_NODE));
assertFalse(gen.isEnabled(XmlWriteFeature.AUTO_DETECT_XSI_TYPE));
assertFalse(gen.isEnabled(XmlWriteFeature.WRITE_XML_SCHEMA_CONFORMING_FLOATS));
// need to write something to the generator to avoid exception
final Point p = new Point(1, 2);
mapper.writeValue(gen, p);
}
final byte[] xml = "<root/>".getBytes(StandardCharsets.UTF_8);
XMLInputFactory inputFactory = mapper.tokenStreamFactory().getXMLInputFactory();
try (
ByteArrayInputStream bis = new ByteArrayInputStream(xml);
FromXmlParser parser =
mapper.createParser(
inputFactory.createXMLStreamReader(bis))
) {
assertFalse(parser.isEnabled(XmlReadFeature.AUTO_DETECT_XSI_TYPE));
}
}
}