This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new bb7c08c  Tests.
bb7c08c is described below

commit bb7c08cccff5bee49bb0121da8a44d042b0c95f9
Author: JamesBognar <[email protected]>
AuthorDate: Thu Apr 9 15:41:50 2020 -0400

    Tests.
---
 .../juneau/SerializerPropertiesComboTest.java      | 33 +++++++++++++++++
 .../java/org/apache/juneau/json/JsonWriter.java    |  6 +++-
 juneau-doc/docs/ReleaseNotes/8.1.4.html            |  2 ++
 .../apache/juneau/rest/client2/RestClientTest.java | 42 +++++++++++++++++++---
 4 files changed, 77 insertions(+), 6 deletions(-)

diff --git 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
index 03467d8..7cd516a 100644
--- 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
+++ 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
@@ -52,6 +52,10 @@ public class SerializerPropertiesComboTest extends 
ComboRoundTripTest {
                public String f;
        }
 
+       public static class T8 {
+               public String f = " foo ";
+       }
+
        @Parameterized.Parameters
        public static Collection<Object[]> getParameters() {
                return Arrays.asList(new Object[][] {
@@ -287,6 +291,35 @@ public class SerializerPropertiesComboTest extends 
ComboRoundTripTest {
                                )
                                
.properties(OMap.of(SERIALIZER_keepNullProperties, true))
                        },
+                       {       /* 8 */
+                               new ComboInput<>(
+                                       "SERIALIZER_trimStrings",
+                                       T8.class,
+                                       new T8(),
+                                       /* Json */              "{f:'foo'}",
+                                       /* JsonT */             "{f:'foo'}",
+                                       /* JsonR */             "{\n\tf: 
'foo'\n}",
+                                       /* Xml */               
"<object><f>foo</f></object>",
+                                       /* XmlT */              
"<object><f>foo</f></object>",
+                                       /* XmlR */              
"<object>\n\t<f>foo</f>\n</object>\n",
+                                       /* XmlNs */             
"<object><f>foo</f></object>",
+                                       /* Html */              
"<table><tr><td>f</td><td>foo</td></tr></table>",
+                                       /* HtmlT */             
"<table><tr><td>f</td><td>foo</td></tr></table>",
+                                       /* HtmlR */             
"<table>\n\t<tr>\n\t\t<td>f</td>\n\t\t<td>foo</td>\n\t</tr>\n</table>\n",
+                                       /* Uon */               "(f=foo)",
+                                       /* UonT */              "(f=foo)",
+                                       /* UonR */              "(\n\tf=foo\n)",
+                                       /* UrlEnc */    "f=foo",
+                                       /* UrlEncT */   "f=foo",
+                                       /* UrlEncR */   "f=foo",
+                                       /* MsgPack */   "81A166A3666F6F",
+                                       /* MsgPackT */  "81A166A3666F6F",
+                                       /* RdfXml */    
"<rdf:RDF>\n<rdf:Description>\n<jp:f>foo</jp:f>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlT */   
"<rdf:RDF>\n<rdf:Description>\n<jp:f>foo</jp:f>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlR */   "<rdf:RDF>\n  
<rdf:Description>\n    <jp:f>foo</jp:f>\n  </rdf:Description>\n</rdf:RDF>\n"
+                               )
+                               .properties(OMap.of(SERIALIZER_trimStrings, 
true))
+                       },
                });
        }
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonWriter.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonWriter.java
index d194090..48af258 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonWriter.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonWriter.java
@@ -128,12 +128,16 @@ public final class JsonWriter extends SerializerWriter {
         * @throws IOException Should never happen.
         */
        public JsonWriter attr(String s) throws IOException {
+
+               if (trimStrings)
+                       s = StringUtils.trim(s);
+
                /*
                 * Converts a Java string to an acceptable JSON attribute name. 
If
                 * simpleMode is true, then quotes will only be used if the 
attribute
                 * name consists of only alphanumeric characters.
                 */
-               boolean doConvert = trimStrings || ! simpleMode;                
// Always convert when not in lax mode.
+               boolean doConvert = ! simpleMode;               // Always 
convert when not in lax mode.
 
                // If the attribute is null, it must always be printed as null 
without quotes.
                // Technically, this isn't part of the JSON spec, but it does 
allow for null key values.
diff --git a/juneau-doc/docs/ReleaseNotes/8.1.4.html 
b/juneau-doc/docs/ReleaseNotes/8.1.4.html
index ec0fba7..3ac98c9 100644
--- a/juneau-doc/docs/ReleaseNotes/8.1.4.html
+++ b/juneau-doc/docs/ReleaseNotes/8.1.4.html
@@ -194,6 +194,8 @@
        <li>
                Fixed bug in HTML serializer where tables of maps were not 
sorted if <jsf>SERIALIZER_sortMaps</jsf> was specified.
        <li>
+               <jsf>SERIALIZER_trimNullProperties</jsf> has been replaced with 
{@link oaj.serializer.Serializer#SERIALIZER_keepNullProperties 
SERIALIZER_keepNullProperties}.
+       <li>
                HTML-Schema support is being deprecated due to low-use and 
difficulty in maintaining.  It will be removed in 9.0.
        <li>
                <c>JuneauLogger</c> class is being deprecated.  Improvements in 
logging in Java 8 make it obsolete.
diff --git 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
index 4651a5f..4af7f45 100644
--- 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
+++ 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
@@ -2450,12 +2450,44 @@ public class RestClientTest {
                        .run()
                        .getBody().assertValue("{}");
        }
-//     public RestClientBuilder trimNullProperties(boolean value) {
 
-//     @Test
-//     public void l21_serializer_trimStringsSBoolean() throws Exception { 
fail(); }
-////   public RestClientBuilder trimStringsS(boolean value) {
-//
+       public static class L21 {
+               public String f = " foo ";
+       }
+
+       @Test
+       public void l21_serializer_trimStringsS() throws Exception {
+               L21 x = new L21();
+
+               MockRestClient
+                       .create(A.class)
+                       .simpleJson()
+                       .trimStringsS()
+                       .build()
+                       .post("/echoBody", x)
+                       .run()
+                       .getBody().assertValue("{f:'foo'}");
+
+               MockRestClient
+                       .create(A.class)
+                       .simpleJson()
+                       .trimStringsS(true)
+                       .build()
+                       .post("/echoBody", x)
+                       .run()
+                       .getBody().assertValue("{f:'foo'}");
+
+               MockRestClient
+                       .create(A.class)
+                       .simpleJson()
+                       .trimStringsS(false)
+                       .build()
+                       .post("/echoBody", x)
+                       .run()
+                       .getBody().assertValue("{f:' foo '}");
+       }
+//     public RestClientBuilder trimStringsS(boolean value) {
+
 //     @Test
 //     public void l22_serializer_trimStringsS() throws Exception { fail(); }
 ////   public RestClientBuilder trimStringsS() {

Reply via email to