forked from FasterXML/jackson-databind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature for QNAME serialization and deserialization.
This commit fixes FasterXML#4771 by adding serialization and deserialization features to control whether a QName is serialized to a string using the "QName.toString()" method (the only option currently) or if it is serialized to JSON object (a new option to fix FasterXML#4771).
- Loading branch information
mcvayc
authored and
mcvayc
committed
Jan 2, 2025
1 parent
f624751
commit d7476c6
Showing
5 changed files
with
107 additions
and
2 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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
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.core.JsonProcessingException; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; | ||
|
||
class QNameAsObjectReadWrite4771Test { | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideAllPerumtationsOfQNameConstructor") | ||
void testQNameWithObjectSerialization(QName originalQName) throws JsonProcessingException { | ||
String json = MAPPER | ||
.disable(SerializationFeature.WRITE_QNAMES_USING_TO_STRING) | ||
.writeValueAsString(originalQName); | ||
|
||
QName deserializedQName = MAPPER | ||
.disable(DeserializationFeature.READ_QNAMES_USING_VALUE_OF) | ||
.readValue(json, QName.class); | ||
|
||
assertEquals(originalQName, deserializedQName); | ||
} | ||
|
||
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")) | ||
); | ||
} | ||
|
||
} |