Repository: vxquery
Updated Branches:
  refs/heads/master bbb50a9d1 -> 5a69a4cb6


VXQUERY-210 Improve json serialization


Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/5a69a4cb
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/5a69a4cb
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/5a69a4cb

Branch: refs/heads/master
Commit: 5a69a4cb61c4fa355b13a20d46a96116c72e9cb0
Parents: bbb50a9
Author: riyafa <[email protected]>
Authored: Tue Aug 2 10:31:46 2016 +0530
Committer: Preston Carman <[email protected]>
Committed: Sun Aug 7 20:29:49 2016 -0700

----------------------------------------------------------------------
 .../vxquery/serializer/XMLSerializer.java       | 43 ++++++++++---
 .../Json/Object/q05_object.txt                  |  2 +-
 .../Json/Object/q18_object.txt                  |  1 +
 .../Queries/XQuery/Json/Object/q18_object.xq    | 64 ++++++++++++++++++++
 .../test/resources/cat/JsonObjectQueries.xml    |  5 ++
 5 files changed, 107 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/5a69a4cb/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java 
b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
index 651572a..ee08891 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
@@ -402,7 +402,7 @@ public class XMLSerializer implements IPrinter {
         UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class);
         TaggedValuePointable tvp = pp.takeOne(TaggedValuePointable.class);
         try {
-            printQuotedString(ps, key);
+            printQuotedTaggedValuePointable(ps, key);
             key.getValue(utf8sp);
             ps.append(":");
             op.getValue(utf8sp, tvp);
@@ -433,16 +433,45 @@ public class XMLSerializer implements IPrinter {
     }
 
     private void printJsonValue(PrintStream ps, TaggedValuePointable tvp) {
-        if (tvp.getTag() == ValueTag.XS_STRING_TAG) {
-            printQuotedString(ps, tvp);
-        } else {
-            printTaggedValuePointable(ps, tvp);
+        int tag = tvp.getTag();
+        switch (tag) {
+            case ValueTag.ARRAY_TAG:
+            case ValueTag.ATTRIBUTE_NODE_TAG:
+            case ValueTag.COMMENT_NODE_TAG:
+            case ValueTag.DOCUMENT_NODE_TAG:
+            case ValueTag.ELEMENT_NODE_TAG:
+            case ValueTag.JS_NULL_TAG:
+            case ValueTag.NODE_TREE_TAG:
+            case ValueTag.OBJECT_TAG:
+            case ValueTag.PI_NODE_TAG:
+            case ValueTag.TEXT_NODE_TAG:
+            case ValueTag.XS_BOOLEAN_TAG:
+            case ValueTag.XS_BYTE_TAG:
+            case ValueTag.XS_DECIMAL_TAG:
+            case ValueTag.XS_DOUBLE_TAG:
+            case ValueTag.XS_FLOAT_TAG:
+            case ValueTag.XS_INT_TAG:
+            case ValueTag.XS_INTEGER_TAG:
+            case ValueTag.XS_LONG_TAG:
+            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_SHORT_TAG:
+            case ValueTag.XS_UNSIGNED_BYTE_TAG:
+            case ValueTag.XS_UNSIGNED_INT_TAG:
+            case ValueTag.XS_UNSIGNED_LONG_TAG:
+            case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                printTaggedValuePointable(ps, tvp);
+                break;
+            default:
+                printQuotedTaggedValuePointable(ps, tvp);
         }
     }
 
-    private void printQuotedString(PrintStream ps, TaggedValuePointable tvp) {
+    private void printQuotedTaggedValuePointable(PrintStream ps, 
TaggedValuePointable tvp) {
         ps.append('\"');
-        printString(ps, tvp);
+        printTaggedValuePointable(ps, tvp);
         ps.append('\"');
     }
 

http://git-wip-us.apache.org/repos/asf/vxquery/blob/5a69a4cb/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q05_object.txt
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q05_object.txt
 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q05_object.txt
index 5dd4417..ec1a421 100644
--- 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q05_object.txt
+++ 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q05_object.txt
@@ -1 +1 @@
-{"a":2016-06-07,"b":2}
\ No newline at end of file
+{"a":"2016-06-07","b":2}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/5a69a4cb/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q18_object.txt
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q18_object.txt
 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q18_object.txt
new file mode 100644
index 0000000..29e6d8c
--- /dev/null
+++ 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q18_object.txt
@@ -0,0 +1 @@
+{"xml":<tra>123</tra>,"array":[1,2,3],"object":{"name":"riyafa"},"boolean":true,"date":"2002-10-10Z","dateTime":"2002-03-06T00:00:00Z","dayTimeDuration":"PT10H","byte":0,"decimal":-3.14,"double":6.022E23,"duration":"P112Y3M","float":0.012345,"gDay":"---10","gMonth":"--05","gMonthDay":"--05-10","gYear":"1999","gYearMonth":"2002-03","hexBinary":"FF","int":42,"unsignedShort":6553,"integer":65537,"long":9223372036854775,"negativeInteger":-99999999999999999,"nonPositiveInteger":-9999999999,"nonNegativeInteger":9999999999,"positiveInteger":9999999999999999,"unsignedInt":429496729,"unsignedLong":9223372036854775,"NOTATION":"prefix:local","short":-6553,"normalizedString":"NCName","token":"foo","language":"en-US","NMTOKEN":"ab","NCname":"foobar","ID":"foo","IDREF":"foo","ENTITY":"entity1","time":"23:02:12Z","sequence":[1,2,3],"attribute":<a
 attr="content"/>,"null":null,"comment":<!-- a comment -->}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/5a69a4cb/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q18_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q18_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q18_object.xq
new file mode 100644
index 0000000..87fe7ef
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q18_object.xq
@@ -0,0 +1,64 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-210 :)
+{
+    "xml" : <tra>123</tra> ,
+    "array" : [1 ,2, 3],
+    "object": {"name": "riyafa"},
+    "boolean": fn:true(),
+    "date" : xs:date("2002-10-10Z"),
+    "dateTime" : xs:dateTime("2002-03-06T00:00:00Z"),
+    "dayTimeDuration" : xs:dayTimeDuration("PT10H"),
+    "byte" : xs:byte(0),
+    "decimal" : xs:decimal(-3.14),
+    "double" : xs:double(6.022E23),
+    "duration" : xs:duration("P0Y1347M0D"),
+    "float" : xs:float('1.2345e-2'),
+    "gDay" : xs:gDay("---10"),
+    "gMonth" : xs:gMonth("--05"),
+    "gMonthDay" : xs:gMonthDay("--05-10"),
+    "gYear" : xs:gYear("1999"),
+    "gYearMonth" : xs:gYearMonth("2002-03"),
+    "hexBinary" : xs:hexBinary("FF"),
+    "int" : xs:int(42),
+    "unsignedShort" : xs:unsignedShort(6553),
+    "integer" : xs:integer(65537),
+    "long" : xs:long("9223372036854775"),
+    "negativeInteger" : xs:negativeInteger("-99999999999999999"),
+    "nonPositiveInteger" : xs:nonPositiveInteger(-9999999999),
+    "nonNegativeInteger" : xs:nonNegativeInteger(9999999999),
+    "positiveInteger" : xs:positiveInteger(9999999999999999),
+    "unsignedInt" : xs:unsignedInt(429496729),
+    "unsignedLong" : xs:unsignedLong(9223372036854775),
+    "NOTATION" : xs:NOTATION("prefix:local"),
+    "short" : xs:short(-6553),
+    "normalizedString" : xs:normalizedString("NCName"),
+    "token" : xs:token("foo"),
+    "language" : xs:language("en-US"),
+    "NMTOKEN" :  xs:NMTOKEN("ab"),
+    "NCname" : xs:NCName("foobar"),
+    "ID" : xs:ID("foo"),
+    "IDREF" : xs:IDREF("foo"),
+    "ENTITY" :  xs:ENTITY("entity1"),
+    "time" : xs:time("23:02:12Z")
+    "sequence" : (1 ,2, 3),
+    "attribute" : <a attr="content"/>,
+    "null" : null,
+    "comment" : <!-- a comment -->
+}

http://git-wip-us.apache.org/repos/asf/vxquery/blob/5a69a4cb/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml 
b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
index fcb01e7..52272fb 100644
--- a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
@@ -105,4 +105,9 @@
         <query name="q17_object" date="2016-07-26"/>
         <expected-error>JNDY0003</expected-error>
     </test-case>
+    <test-case name="json-object-q18" FilePath="Json/Object/" Creator="Riyafa 
Abdul Hameed">
+        <description>Object.</description>
+        <query name="q18_object" date="2016-07-17"/>
+        <output-file compare="Text">q18_object.txt</output-file>
+    </test-case>
 </test-group>
\ No newline at end of file

Reply via email to