-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
1 parent
1c3565e
commit 3ad3995
Showing
5 changed files
with
82 additions
and
15 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
63 changes: 63 additions & 0 deletions
63
src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/NamespaceViaJAXB18Test.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,63 @@ | ||
package com.fasterxml.jackson.dataformat.xml.jaxb; | ||
|
||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
public class NamespaceViaJAXB18Test extends XmlTestBase | ||
{ | ||
final static String TEST_NAMESPACE = "http://namespace-base"; | ||
|
||
@XmlRootElement(namespace = TEST_NAMESPACE) | ||
interface Facility { } | ||
|
||
static class House implements Facility { | ||
@XmlAttribute | ||
public String getName() { return "Bob"; } | ||
} | ||
|
||
@XmlRootElement(namespace = "", name = "Houzz") | ||
static class HouseWithNoNamespace implements Facility { | ||
@XmlAttribute | ||
public String getName() { return "Bill"; } | ||
} | ||
|
||
// Also: for better or worse, cannot only override local name so: | ||
@XmlRootElement(name = "Houzz2") | ||
static class HouseWithNoNamespace2 implements Facility { | ||
@XmlAttribute | ||
public String getName() { return "Frank"; } | ||
} | ||
|
||
private final XmlMapper MAPPER = mapperBuilder() | ||
.annotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())) | ||
.build(); | ||
|
||
// [dataformat-xml#18] | ||
public void testNamespaceViaJAXB() throws Exception | ||
{ | ||
String xml = MAPPER.writeValueAsString(new House()); | ||
if (!xml.contains("<House xmlns") | ||
|| !xml.contains(TEST_NAMESPACE)) { | ||
fail("Expected `xmlns` declaration for element `House`, none seen: XML = "+xml); | ||
} | ||
|
||
// But should be able to mask it... | ||
xml = MAPPER.writeValueAsString(new HouseWithNoNamespace()); | ||
if (!xml.contains("<Houzz") | ||
|| xml.contains("xmlns")) { | ||
fail("Expected NO `xmlns` declaration for element `Houzz` but got XML = "+xml); | ||
} | ||
|
||
xml = MAPPER.writeValueAsString(new HouseWithNoNamespace2()); | ||
if (!xml.contains("<Houzz2") | ||
|| xml.contains("xmlns")) { | ||
fail("Expected NO `xmlns` declaration for element `Houzz2` but got XML = "+xml); | ||
} | ||
} | ||
} |
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