-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #4771: Support OBJECT shape for QNAME serialization and deseriali…
…zation. (#4968)
- Loading branch information
Showing
5 changed files
with
216 additions
and
5 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
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
57 changes: 57 additions & 0 deletions
57
src/test/java/com/fasterxml/jackson/databind/ext/QNameAsObjectReadWrite4771Test.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,57 @@ | ||
package com.fasterxml.jackson.databind.ext; | ||
|
||
import java.util.stream.Stream; | ||
import javax.xml.namespace.QName; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class QNameAsObjectReadWrite4771Test extends DatabindTestUtil | ||
{ | ||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
static class BeanWithQName { | ||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) | ||
public QName qname; | ||
|
||
BeanWithQName() { } | ||
|
||
public BeanWithQName(QName qName) { | ||
this.qname = qName; | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideAllPerumtationsOfQNameConstructor") | ||
void testQNameWithObjectSerialization(QName originalQName) throws JsonProcessingException | ||
{ | ||
BeanWithQName bean = new BeanWithQName(originalQName); | ||
|
||
String json = MAPPER.writeValueAsString(bean); | ||
|
||
QName deserializedQName = MAPPER.readValue(json, BeanWithQName.class).qname; | ||
|
||
assertEquals(originalQName.getLocalPart(), deserializedQName.getLocalPart()); | ||
assertEquals(originalQName.getNamespaceURI(), deserializedQName.getNamespaceURI()); | ||
assertEquals(originalQName.getPrefix(), deserializedQName.getPrefix()); | ||
} | ||
|
||
static Stream<Arguments> provideAllPerumtationsOfQNameConstructor() | ||
{ | ||
return Stream.of( | ||
Arguments.of(new QName("test-local-part")), | ||
Arguments.of(new QName("test-namespace-uri", "test-local-part")), | ||
Arguments.of(new QName("test-namespace-uri", "test-local-part", "test-prefix")) | ||
); | ||
} | ||
} |