Skip to content

Commit

Permalink
fix #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael Sokolov committed Apr 12, 2022
1 parent 078a6be commit dacb1e3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<properties>
<java.version>1.8</java.version>
<kotlin.version>1.5.30</kotlin.version>
<jackson.version>2.12.5</jackson.version>
<kotlin.version>1.6.20</kotlin.version>
<jackson.version>2.13.2</jackson.version>

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down Expand Up @@ -136,7 +136,7 @@
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.4.4</version>
<version>3.5.2</version>
<executions>
<execution>
<id>generate-sources</id>
Expand Down Expand Up @@ -230,7 +230,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.3.2</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -243,7 +243,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.5.30</version>
<version>1.6.10</version>
<executions>
<execution>
<phase>pre-site</phase>
Expand Down Expand Up @@ -285,7 +285,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.12</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.sokomishalov.jackson.dataformat.soap

import com.fasterxml.jackson.databind.SerializationConfig
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider
import com.fasterxml.jackson.databind.ser.SerializerFactory
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator
import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider
import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup
import javax.xml.XMLConstants.NULL_NS_URI
import javax.xml.namespace.QName

internal class AlwaysUseNamespacesXmlSerializerProvider : XmlSerializerProvider {

internal constructor() : super(XmlRootNameLookup())
internal constructor(src: XmlSerializerProvider, config: SerializationConfig?, f: SerializerFactory?) : super(src, config, f)

override fun createInstance(config: SerializationConfig?, jsf: SerializerFactory?): DefaultSerializerProvider {
return AlwaysUseNamespacesXmlSerializerProvider(this, config, jsf)
}

override fun _initWithRootName(xgen: ToXmlGenerator, rootName: QName?) {
super._initWithRootName(xgen, rootName)
xgen.staxWriter.setDefaultNamespace(NULL_NS_URI)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ru.sokomishalov.jackson.dataformat.soap

import com.fasterxml.jackson.databind.PropertyName
import com.fasterxml.jackson.databind.PropertyName.NO_NAME
import com.fasterxml.jackson.databind.cfg.MapperConfig
import com.fasterxml.jackson.databind.introspect.Annotated
import com.fasterxml.jackson.databind.type.TypeFactory
import com.fasterxml.jackson.databind.util.ClassUtil
Expand All @@ -30,12 +31,9 @@ import javax.xml.bind.annotation.XmlAttribute
import javax.xml.bind.annotation.XmlElement
import javax.xml.bind.annotation.XmlElementWrapper

open class SoapJaxbAnnotationIntrospector : JaxbAnnotationIntrospector(TypeFactory.defaultInstance()) {

open class SoapJaxbAnnotationIntrospector @JvmOverloads constructor(
typeFactory: TypeFactory = TypeFactory.defaultInstance()
) : JaxbAnnotationIntrospector(typeFactory) {

override fun findNamespace(ann: Annotated): String? = ann.rawType?.let { t ->
override fun findNamespace(config: MapperConfig<*>?, ann: Annotated?): String? = ann?.rawType?.let { t ->
val annotationNamespace = ann.annotated.getAnnotation(XmlElement::class.java)?.namespace

when {
Expand All @@ -54,7 +52,7 @@ open class SoapJaxbAnnotationIntrospector @JvmOverloads constructor(
}

override fun findNullSerializer(ann: Annotated?): Any? = when {
isOutputAsAttribute(ann) == true -> null
isOutputAsAttribute(null, ann) == true -> null
else -> SoapEnvelopeSerializers.XsiNilSerializer
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package ru.sokomishalov.jackson.dataformat.soap

import com.ctc.wstx.stax.WstxOutputFactory
import com.fasterxml.jackson.databind.DeserializationFeature.*
import com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS
import com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS
import com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
import com.fasterxml.jackson.databind.type.TypeFactory
import com.fasterxml.jackson.dataformat.xml.XmlFactory
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
import org.codehaus.stax2.XMLOutputFactory2.P_AUTOMATIC_NS_PREFIX
import ru.sokomishalov.jackson.dataformat.soap.SoapConstants.SOAP_11_ENVELOPE_NAMESPACE
import ru.sokomishalov.jackson.dataformat.soap.deser.SoapEnvelopeDeserializers
import ru.sokomishalov.jackson.dataformat.soap.ser.SoapEnvelopeSerializers
Expand All @@ -38,18 +38,19 @@ import ru.sokomishalov.jackson.dataformat.soap.ser.SoapEnvelopeSerializers
open class SoapModule @JvmOverloads constructor(
private val namespacePrefix: String = "ns",
private val soapEnvelopeNamespace: String = SOAP_11_ENVELOPE_NAMESPACE
) : JaxbAnnotationModule(SoapJaxbAnnotationIntrospector(TypeFactory.defaultInstance())) {
) : JaxbAnnotationModule(SoapJaxbAnnotationIntrospector()) {

override fun setupModule(context: SetupContext) {
with(context) {
addSerializers(SoapEnvelopeSerializers(soapEnvelopeNamespace))
addDeserializers(SoapEnvelopeDeserializers())
getOwner<ObjectMapper>().apply {
setSerializerProvider(AlwaysUseNamespacesXmlSerializerProvider())
enable(ACCEPT_SINGLE_VALUE_AS_ARRAY, ACCEPT_FLOAT_AS_INT)
enable(ACCEPT_CASE_INSENSITIVE_PROPERTIES)
enable(ACCEPT_CASE_INSENSITIVE_PROPERTIES, ACCEPT_CASE_INSENSITIVE_ENUMS)
disable(FAIL_ON_EMPTY_BEANS, WRITE_DATES_AS_TIMESTAMPS)
disable(FAIL_ON_READING_DUP_TREE_KEY, FAIL_ON_UNKNOWN_PROPERTIES)
(factory as? XmlFactory)?.xmlOutputFactory?.setProperty(P_AUTOMATIC_NS_PREFIX, namespacePrefix)
disable(FAIL_ON_UNKNOWN_PROPERTIES, FAIL_ON_READING_DUP_TREE_KEY)
((factory as? XmlFactory)?.xmlOutputFactory as? WstxOutputFactory)?.apply { config.automaticNsPrefix = namespacePrefix }
}
super.setupModule(this)
}
Expand Down

0 comments on commit dacb1e3

Please sign in to comment.