-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
proteus-core/src/main/java/io/sinistral/proteus/modules/XmlModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.sinistral.proteus.modules; | ||
|
||
import com.ctc.wstx.api.WstxInputProperties; | ||
import com.ctc.wstx.api.WstxOutputProperties; | ||
import com.ctc.wstx.stax.WstxInputFactory; | ||
import com.ctc.wstx.stax.WstxOutputFactory; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlFactory; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; | ||
import com.google.inject.AbstractModule; | ||
|
||
import javax.xml.stream.XMLInputFactory; | ||
import javax.xml.stream.XMLOutputFactory; | ||
|
||
public class XmlModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
|
||
XMLInputFactory inputFactory = new WstxInputFactory(); | ||
inputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, 32000); | ||
|
||
bind(XMLInputFactory.class).toInstance(inputFactory); | ||
|
||
XMLOutputFactory outputFactory = new WstxOutputFactory(); | ||
outputFactory.setProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT, true); | ||
|
||
bind(XMLOutputFactory.class).toInstance(outputFactory); | ||
|
||
XmlFactory xmlFactory = new XmlFactory(inputFactory, outputFactory); | ||
|
||
XmlMapper xmlMapper = new XmlMapper(xmlFactory); | ||
xmlMapper.registerModule(new JavaTimeModule()) | ||
.registerModule(new ParameterNamesModule()) | ||
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
|
||
xmlMapper.enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION); | ||
|
||
bind(XmlMapper.class).toInstance(xmlMapper); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters