Skip to content

Commit

Permalink
Further cleanup wrt #531
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 13, 2022
1 parent 5ea4f3b commit 50282e0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected XmlFactory(XmlFactoryBuilder b)
_cfgNameForTextElement = b.nameForTextElement();
_xmlInputFactory = b.xmlInputFactory();
_xmlOutputFactory = b.xmlOutputFactory();
_nameProcessor = b.xmlTagProcessor();
_nameProcessor = b.xmlNameProcessor();
_initFactories(_xmlInputFactory, _xmlOutputFactory);
}

Expand Down Expand Up @@ -336,11 +336,11 @@ public int getFormatGeneratorFeatures() {
return _xmlGeneratorFeatures;
}

public XmlNameProcessor getXmlTagProcessor() {
public XmlNameProcessor getXmlNameProcessor() {
return _nameProcessor;
}

public void setXmlTagProcessor(XmlNameProcessor processor) {
public void setXmlNameProcessor(XmlNameProcessor processor) {
_nameProcessor = processor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected ClassLoader staxClassLoader() {
getClass().getClassLoader() : _classLoaderForStax;
}

public XmlNameProcessor xmlTagProcessor() {
public XmlNameProcessor xmlNameProcessor() {
return _nameProcessor;
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public XmlFactoryBuilder staxClassLoader(ClassLoader cl) {
/**
* @since 2.14
*/
public XmlFactoryBuilder xmlTagProcessor(XmlNameProcessor nameProcessor) {
public XmlFactoryBuilder xmlNameProcessor(XmlNameProcessor nameProcessor) {
_nameProcessor = nameProcessor;
return _this();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public XmlMapper setDefaultUseWrapper(boolean state) {
* @since 2.14
*/
public void setXmlNameProcessor(XmlNameProcessor processor) {
((XmlFactory)_jsonFactory).setXmlTagProcessor(processor);
((XmlFactory)_jsonFactory).setXmlNameProcessor(processor);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private XmlNameProcessors() {
* @since 2.14
*/
public static XmlNameProcessor newPassthroughProcessor() {
return new PassthroughTagProcessor();
return new PassthroughProcessor();
}

/**
Expand Down Expand Up @@ -157,10 +157,10 @@ public static XmlNameProcessor newAlwaysOnBase64Processor() {
return new AlwaysOnBase64NameProcessor();
}

static class PassthroughTagProcessor implements XmlNameProcessor {
static class PassthroughProcessor implements XmlNameProcessor {
private static final long serialVersionUID = 1L;

public PassthroughTagProcessor() { }
public PassthroughProcessor() { }

@Override
public void encodeName(XmlName name) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
* token (for consistency with how XML is mapper to tokens); this leads to deserialization
* attempting to use "empty Object" construction which expects availability of the
* default constructor.
* To resolve the issue there are at least two possible ways:
*<ul>
* <li>Try to make root element appears as START-OBJECT/END-OBJECT sequence instead of VALUE_STRING
* </li>
* <li>Change {@code StdDeserializer} (from jackson-databind) to allow use of "properties-based"
* Creator as well -- passing equivalent of all-absent values. This could either be for all
* content, or just for specific formats (using a {@code StreamReadFeature} to detect).
* </li>
*</ul>
* Either approach could work, although former could cause other kinds of regression.
*<p>
* Jackson 2.14 solved this issue by reverting earlier changes so that empty element
* is exposed as simple START_OBJECT/END_OBJECT sequence (that is, empty Object).
* Use cases where (non-empty) element needs to map to Scalar types is now handled
* with mechanism introduced in 2.13.
*/
public class NoArgCtorDeser491Test extends XmlTestBase
{
Expand Down Expand Up @@ -101,12 +96,16 @@ public void test_empty_Problem_JSON_deserialization() throws Exception
public void test_empty_Problem_XML_deserialization() throws Exception
{
Problem problem = XML_MAPPER.readValue(
// This WOULD work:
// "<problem><status>500</status></problem>",
// but not missing
"<problem />",
Problem.class);
assertEquals(Problem.DEFAULT_TYPE, problem.getType());
assertEquals(Problem.DEFAULT_STATUS, problem.getStatus());

// Also ensure variations of empty do not vary
problem = XML_MAPPER.readValue(
"<problem>\n</problem>",
Problem.class);
assertEquals(Problem.DEFAULT_TYPE, problem.getType());
assertEquals(Problem.DEFAULT_STATUS, problem.getStatus());
}
}

0 comments on commit 50282e0

Please sign in to comment.