cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7004] Updating the basic json writer to drop quotes only if it is Number, Boolean or custom JsonObject
Date Thu, 11 Aug 2016 09:38:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 7c3038997 -> 96ff2ac50


[CXF-7004] Updating the basic json writer to drop quotes only if it is Number, Boolean or
custom JsonObject


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/96ff2ac5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/96ff2ac5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/96ff2ac5

Branch: refs/heads/master
Commit: 96ff2ac50c0822d55fbbb169d22352c8db964e41
Parents: 7c30389
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Aug 11 10:38:22 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Aug 11 10:38:22 2016 +0100

----------------------------------------------------------------------
 .../json/basic/JsonMapObjectReaderWriter.java   | 11 +++++++---
 .../apache/cxf/jaxrs/json/basic/JsonObject.java | 23 ++++++++++++++++++++
 .../basic/JsonMapObjectReaderWriterTest.java    |  8 +++++++
 .../jose/jwe/JweJsonEncryptionEntry.java        |  3 ++-
 .../jose/jws/JwsJsonSignatureEntry.java         |  3 ++-
 5 files changed, 43 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/96ff2ac5/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
index b311ede..d1fb1f5 100644
--- a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
+++ b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriter.java
@@ -107,12 +107,12 @@ public class JsonMapObjectReaderWriter {
         } else if (Map.class.isAssignableFrom(value.getClass())) {
             toJsonInternal(out, (Map<String, Object>)value);
         } else {
-            boolean stringOrEnum = value.getClass() == String.class || value.getClass().isEnum();
-            if (stringOrEnum) {
+            boolean quotesNeeded = checkQuotesNeeded(value);
+            if (quotesNeeded) {
                 out.append("\"");
             }
             out.append(value.toString());
-            if (stringOrEnum) {
+            if (quotesNeeded) {
                 out.append("\"");
             }
         }
@@ -123,6 +123,11 @@ public class JsonMapObjectReaderWriter {
         
     }
     
+    private boolean checkQuotesNeeded(Object value) {
+        Class<?> cls = value.getClass();
+        return !(Number.class.isAssignableFrom(cls) || Boolean.class == cls
+            || JsonObject.class.isAssignableFrom(cls));
+    }
     protected void formatIfNeeded(Output out) {
         if (format) {
             out.append("\r\n ");

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ff2ac5/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonObject.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonObject.java
b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonObject.java
new file mode 100644
index 0000000..c8be2f8
--- /dev/null
+++ b/rt/rs/extensions/json-basic/src/main/java/org/apache/cxf/jaxrs/json/basic/JsonObject.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.json.basic;
+
+public interface JsonObject {
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ff2ac5/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
b/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
index 4f03acb..afb81d9 100644
--- a/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
+++ b/rt/rs/extensions/json-basic/src/test/java/org/apache/cxf/jaxrs/json/basic/JsonMapObjectReaderWriterTest.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.json.basic;
 
 import java.util.Collections;
+import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -40,6 +41,13 @@ public class JsonMapObjectReaderWriterTest extends Assert {
                      json);
     }
     @Test
+    public void testWriteDateProperty() throws Exception {
+        Date date = new Date();
+        Map<String, Object> map = Collections.singletonMap("createdAt", date);
+        String json = new JsonMapObjectReaderWriter().toJson(map);
+        assertEquals("{\"createdAt\":\"" + date.toString() + "\"}", json);
+    }
+    @Test
     public void testReadMap() throws Exception {
         String json = "{\"a\":\"aValue\",\"b\":123,\"c\":[\"cValue\"],\"f\":null}";
         Map<String, Object> map = new JsonMapObjectReaderWriter().fromJson(json);

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ff2ac5/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJsonEncryptionEntry.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJsonEncryptionEntry.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJsonEncryptionEntry.java
index d744892..f13502e 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJsonEncryptionEntry.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJsonEncryptionEntry.java
@@ -22,9 +22,10 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
+import org.apache.cxf.jaxrs.json.basic.JsonObject;
 import org.apache.cxf.rs.security.jose.common.JoseUtils;
 
-public class JweJsonEncryptionEntry {
+public class JweJsonEncryptionEntry implements JsonObject {
     private JweHeaders unprotectedHeader;
     private String encodedEncryptedKey;
     public JweJsonEncryptionEntry(String encodedEncryptedKey) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ff2ac5/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJsonSignatureEntry.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJsonSignatureEntry.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJsonSignatureEntry.java
index 85f89df..4b66498 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJsonSignatureEntry.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJsonSignatureEntry.java
@@ -25,12 +25,13 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.Base64UrlUtility;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
+import org.apache.cxf.jaxrs.json.basic.JsonObject;
 import org.apache.cxf.rs.security.jose.common.JoseConstants;
 import org.apache.cxf.rs.security.jose.common.JoseUtils;
 import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
 
 
-public class JwsJsonSignatureEntry {
+public class JwsJsonSignatureEntry implements JsonObject {
     protected static final Logger LOG = LogUtils.getL7dLogger(JwsJsonSignatureEntry.class);
     private String jwsPayload;
     private String encodedProtectedHeader;


Mime
View raw message