Skip to content

Commit

Permalink
Fix #678: allow configuring custom SerializerFactory via JacksonXmlMo…
Browse files Browse the repository at this point in the history
…dule (#680)
  • Loading branch information
cowtowncoder authored Nov 4, 2024
1 parent 180a75b commit 5b78983
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-dataformat-xml
=== Releases ===
------------------------------------------------------------------------

2.18.2 (not yet released)

#678: XML module not registered correctly when setting a custom `SerializerFactory`
(reported by @SimonCockx)

2.18.1 (28-Oct-2024)

No changes since 2.18.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.module.SimpleModule;

import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import com.fasterxml.jackson.dataformat.xml.deser.XmlBeanDeserializerModifier;
import com.fasterxml.jackson.dataformat.xml.ser.XmlBeanSerializerModifier;
Expand Down Expand Up @@ -39,13 +39,22 @@ public class JacksonXmlModule
/**
* Name used for pseudo-property used for returning XML Text value (which does
* not have actual element name to use). Defaults to empty String, but
* may be changed for interoperability reasons: JAXB, for example, uses
* may be changed for inter-operability reasons: JAXB, for example, uses
* "value" as name.
*
* @since 2.1
*/
protected String _cfgNameForTextElement = FromXmlParser.DEFAULT_UNNAMED_TEXT_PROPERTY;


/**
* Optional override for {@link SerializerFactory}
* used by {@link XmlMapper}. Needed to allow proper override and configurability
* using custom {@SerializerFactory} implementations.
*
* @since 2.18.2
*/
protected SerializerFactory _serializerFactoryOverride;

/*
/**********************************************************************
/* Life-cycle: construction
Expand Down Expand Up @@ -119,6 +128,29 @@ public void setDefaultUseWrapper(boolean state) {
public void setXMLTextElementName(String name) {
_cfgNameForTextElement = name;
}

/**
* Method to use for overriding default {@link SerializerFactory} used
*
* @since 2.18.2
*/
public JacksonXmlModule overrideSerializerFactory(SerializerFactory factory) {
_serializerFactoryOverride = factory;
return this;
}

/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/

/**
* @since 2.18.2
*/
public SerializerFactory serializerFactoryOverride() {
return _serializerFactoryOverride;
}

/*
/**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.fasterxml.jackson.databind.deser.BeanDeserializerFactory;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.type.LogicalType;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import com.fasterxml.jackson.dataformat.xml.deser.XmlDeserializationContext;
Expand Down Expand Up @@ -166,6 +167,11 @@ public XmlMapper(XmlFactory xmlFactory, JacksonXmlModule module)
_xmlModule = module;
// but all the rest is done via Module interface!
if (module != null) {
// [dataformat-xml#678]: need special handling for SerializerFactory override
SerializerFactory sfOverride = module.serializerFactoryOverride();
if (sfOverride != null) {
setSerializerFactory(sfOverride);
}
registerModule(module);
}
// 19-May-2015, tatu: Must ensure we use XML-specific indenter
Expand Down

0 comments on commit 5b78983

Please sign in to comment.