[teiid-commits] teiid SVN: r2907 - in trunk: engine/src/main/java/org/teiid/query/function/source and 1 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Mon Feb 14 22:12:22 EST 2011
Author: shawkins
Date: 2011-02-14 22:12:21 -0500 (Mon, 14 Feb 2011)
New Revision: 2907
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
Log:
TEIID-1306 adding xsi:nil for null handling
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2011-02-14 20:34:03 UTC (rev 2906)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2011-02-15 03:12:21 UTC (rev 2907)
@@ -1948,6 +1948,9 @@
<listitem>
<para>Unless an array value is the root, it will not be enclosed in an additional element.</para>
</listitem>
+ <listitem>
+ <para>Null values will be represented by an empty element with the attribute xsi:nil="true"</para>
+ </listitem>
</itemizedlist>
</para>
<example>
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2011-02-14 20:34:03 UTC (rev 2906)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2011-02-15 03:12:21 UTC (rev 2907)
@@ -171,12 +171,15 @@
if (inArray.peek()) {
start();
}
- if (value != null) {
- try {
+ try {
+ if (value != null) {
streamWriter.writeCharacters(value.toString());
- } catch (XMLStreamException e) {
- throw new IOException(e);
+ } else {
+ streamWriter.writeNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); //$NON-NLS-1$
+ streamWriter.writeAttribute("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil", "true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
}
if (inArray.peek()) {
end();
Modified: trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2011-02-14 20:34:03 UTC (rev 2906)
+++ trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2011-02-15 03:12:21 UTC (rev 2907)
@@ -218,6 +218,12 @@
helpTestJson(json, "Person", expected);
}
+ @Test public void testJsonToXml2() throws Exception {
+ String json = "{ \"firstName\": null }";
+ String expected = "<?xml version=\"1.0\" ?><Person><firstName xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"></firstName></Person>";
+ helpTestJson(json, "Person", expected);
+ }
+
@BeforeClass static public void setUpOnce() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00"));
}
More information about the teiid-commits
mailing list