This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Jackson's XML QName parser to the correct namespace (#605)
* Mapping QName to the correct namespace. * Import cleanup
- Loading branch information
1 parent
ac9e80c
commit db59f30
Showing
7 changed files
with
132 additions
and
0 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
33 changes: 33 additions & 0 deletions
33
...g/opencds/cqf/cql/engine/serializing/jackson/modules/QNameFixerXMLMapperDeserializer.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,33 @@ | ||
package org.opencds.cqf.cql.engine.serializing.jackson.modules; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JacksonException; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser; | ||
|
||
public class QNameFixerXMLMapperDeserializer extends JsonDeserializer<QName> { | ||
JsonDeserializer<?> originalDeserializer; | ||
public QNameFixerXMLMapperDeserializer(JsonDeserializer<?> deserializer) { | ||
originalDeserializer = deserializer; | ||
} | ||
|
||
@Override | ||
public QName deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException { | ||
var qName = (QName) originalDeserializer.deserialize(jsonParser, deserializationContext); | ||
|
||
if (qName.getLocalPart().indexOf(":") > 0) { | ||
var prefix = qName.getLocalPart().split(":")[0]; | ||
var localPart = qName.getLocalPart().split(":")[1]; | ||
var namespace = ((FromXmlParser)deserializationContext.getParser()).getStaxReader().getNamespaceContext().getNamespaceURI(prefix); | ||
|
||
return new QName(namespace, localPart, prefix); | ||
} | ||
|
||
return qName; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...a/org/opencds/cqf/cql/engine/serializing/jackson/modules/QNameFixerXMLMapperModifier.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,17 @@ | ||
package org.opencds.cqf.cql.engine.serializing.jackson.modules; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import com.fasterxml.jackson.databind.BeanDescription; | ||
import com.fasterxml.jackson.databind.DeserializationConfig; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; | ||
|
||
public class QNameFixerXMLMapperModifier extends BeanDeserializerModifier { | ||
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { | ||
if (beanDesc.getBeanClass() == QName.class) { | ||
return new QNameFixerXMLMapperDeserializer(deserializer); | ||
} | ||
return super.modifyDeserializer(config, beanDesc, deserializer); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...e.jackson/src/test/java/org/opencds/cqf/cql/engine/serializing/QNameIssueJacksonTest.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,26 @@ | ||
package org.opencds.cqf.cql.engine.serializing; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.cqframework.cql.cql2elm.LibraryContentType; | ||
import org.cqframework.cql.elm.execution.IntervalTypeSpecifier; | ||
import org.cqframework.cql.elm.execution.NamedTypeSpecifier; | ||
import org.testng.annotations.Test; | ||
|
||
public class QNameIssueJacksonTest { | ||
@Test | ||
void loaderIsAvailable() throws IOException { | ||
var lib = | ||
CqlLibraryReaderFactory.getReader(LibraryContentType.XML.mimeType()) | ||
.read(QNameIssueJacksonTest.class.getResourceAsStream("QNameIssue.xml")); | ||
|
||
var actual = ((NamedTypeSpecifier) | ||
((IntervalTypeSpecifier) lib.getParameters().getDef().get(0).getParameterTypeSpecifier()).getPointType() | ||
).getName(); | ||
|
||
assertEquals("{urn:hl7-org:elm-types:r1}DateTime", actual.toString()); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
engine.jackson/src/test/resources/org/opencds/cqf/cql/engine/serializing/QNameIssue.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<library | ||
xmlns="urn:hl7-org:elm:r1" | ||
xmlns:t="urn:hl7-org:elm-types:r1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<parameters> | ||
<def localId="25" locator="25:1-26:66" name="Measurement Period" accessLevel="Public"> | ||
<parameterTypeSpecifier localId="24" locator="25:32-25:49" xsi:type="IntervalTypeSpecifier"> | ||
<pointType localId="23" locator="25:41-25:48" name="t:DateTime" xsi:type="NamedTypeSpecifier"/> | ||
</parameterTypeSpecifier> | ||
</def> | ||
</parameters> | ||
</library> |
26 changes: 26 additions & 0 deletions
26
engine.jaxb/src/test/java/org/opencds/cqf/cql/engine/serializing/QNameIssueJaxbTest.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,26 @@ | ||
package org.opencds.cqf.cql.engine.serializing; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.cqframework.cql.cql2elm.LibraryContentType; | ||
import org.cqframework.cql.elm.execution.IntervalTypeSpecifier; | ||
import org.cqframework.cql.elm.execution.NamedTypeSpecifier; | ||
import org.testng.annotations.Test; | ||
|
||
public class QNameIssueJaxbTest { | ||
@Test | ||
void loaderIsAvailable() throws IOException { | ||
var lib = | ||
CqlLibraryReaderFactory.getReader(LibraryContentType.XML.mimeType()) | ||
.read(QNameIssueJaxbTest.class.getResourceAsStream("QNameIssue.xml")); | ||
|
||
var actual = ((NamedTypeSpecifier) | ||
((IntervalTypeSpecifier) lib.getParameters().getDef().get(0).getParameterTypeSpecifier()).getPointType() | ||
).getName(); | ||
|
||
assertEquals("{urn:hl7-org:elm-types:r1}DateTime", actual.toString()); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
engine.jaxb/src/test/resources/org/opencds/cqf/cql/engine/serializing/QNameIssue.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<library | ||
xmlns="urn:hl7-org:elm:r1" | ||
xmlns:t="urn:hl7-org:elm-types:r1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<parameters> | ||
<def localId="25" locator="25:1-26:66" name="Measurement Period" accessLevel="Public"> | ||
<parameterTypeSpecifier localId="24" locator="25:32-25:49" xsi:type="IntervalTypeSpecifier"> | ||
<pointType localId="23" locator="25:41-25:48" name="t:DateTime" xsi:type="NamedTypeSpecifier"/> | ||
</parameterTypeSpecifier> | ||
</def> | ||
</parameters> | ||
</library> |