Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#233 XmlMapper.copy() doesn't properly copy internal configurations #234

Merged
merged 2 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ public XmlMapper(XmlFactory xmlFactory, JacksonXmlModule module)
_serializationConfig = _serializationConfig.withDefaultPrettyPrinter(DEFAULT_XML_PRETTY_PRINTER);
}

protected XmlMapper(XmlMapper mapper) {
super(mapper);
this._xmlModule = mapper._xmlModule;
}

@Override
public XmlMapper copy()
{
_checkInvalidCopy(XmlMapper.class);
return new XmlMapper((XmlFactory) _jsonFactory.copy(), _xmlModule);
return new XmlMapper(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ public XmlSerializerProvider(XmlSerializerProvider src,
_rootNameLookup = src._rootNameLookup;
}

protected XmlSerializerProvider(XmlSerializerProvider toCopy) {
super(toCopy);
this._rootNameLookup = toCopy._rootNameLookup;
}

/*
/**********************************************************************
/* Overridden methods
/**********************************************************************
*/

@Override
public DefaultSerializerProvider copy() {
return new XmlSerializerProvider(this);
}

@Override
public DefaultSerializerProvider createInstance(SerializationConfig config,
SerializerFactory jsf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.dataformat.xml.PackageVersion;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider;
import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup;

public class VersionInfoTest extends XmlTestBase
{
Expand All @@ -24,7 +26,8 @@ public void testMapperCopy()
XmlMapper mapper1 = new XmlMapper();
mapper1.setXMLTextElementName("foo");
mapper1.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);

mapper1.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

XmlMapper mapper2 = mapper1.copy();
assertNotSame(mapper1, mapper2);
XmlFactory xf1 = mapper1.getFactory();
Expand All @@ -36,6 +39,22 @@ public void testMapperCopy()
assertEquals(xf1.getXMLTextElementName(), xf2.getXMLTextElementName());
assertEquals(xf1._xmlGeneratorFeatures, xf2._xmlGeneratorFeatures);
assertEquals(xf1._xmlParserFeatures, xf2._xmlParserFeatures);

// and [Issue#233]
SerializationConfig sc1 = mapper1.getSerializationConfig();
SerializationConfig sc2 = mapper2.getSerializationConfig();
assertNotSame(sc1, sc2);
assertEquals(
"serialization features did not get copied",
sc1.getSerializationFeatures(),
sc2.getSerializationFeatures()
);
}

public void testSerializerProviderCopy() {
DefaultSerializerProvider provider = new XmlSerializerProvider(new XmlRootNameLookup());
DefaultSerializerProvider copy = provider.copy();
assertNotSame(provider, copy);
}

// Another test for [Issue#48]
Expand Down