You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@juneau.apache.org by GitBox <gi...@apache.org> on 2018/12/12 20:08:27 UTC

[GitHub] jamesbognar closed pull request #33: adding xml serializer configuration example and doc changes

jamesbognar closed pull request #33: adding xml serializer configuration example and doc changes
URL: https://github.com/apache/juneau/pull/33
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/juneau-doc/docs/Topics/15.juneau-examples-core/01.Examples.html b/juneau-doc/docs/Topics/15.juneau-examples-core/01.Examples.html
index f2a9b5bd4..5dd6d37cd 100644
--- a/juneau-doc/docs/Topics/15.juneau-examples-core/01.Examples.html
+++ b/juneau-doc/docs/Topics/15.juneau-examples-core/01.Examples.html
@@ -23,12 +23,13 @@
 	<ul>
 		<li class='jc'>{@link oaj.examples.core.json.JsonSimpleExample} - JsonSerializer and JsonParser usage on serialize and deserialize simple Pojo bean.
 		<li class='jc'>{@link oaj.examples.core.json.JsonComplexExample} - JsonSerializer and JsonParser usage on serialize and deserialize complex Pojo bean.
-		<li class='jc'>{@link oaj.examples.core.json.JsonConfigurationExample} 
+		<li class='jc'>{@link oaj.examples.core.json.JsonConfigurationExample} - Json Serializers configured using properties defined in JsonSerializer class.
 	</ul>
 	<li class='jp'>{@link oaj.examples.core.xml}
 	<ul>
 		<li class='jc'>{@link oaj.examples.core.xml.XmlSimpleExample} - XmlSerializer and XmlParser usage on serialize and deserialize simple Pojo bean.
 		<li class='jc'>{@link oaj.examples.core.xml.XmlComplexExample} - XmlSerializer and XmlParser usage on serialize and deserialize complex Pojo bean.
+		<li class='jc'>{@link oaj.examples.core.xml.XmlConfigurationExample} - XmlSerializers configured using properties defined in XmlSerializer class.
 	</ul>
 	<li class='jp'>{@link oaj.examples.core.rdf}
 	<ul>
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonConfigurationExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonConfigurationExample.java
index b4c5750bf..a5bc373e1 100644
--- a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonConfigurationExample.java
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonConfigurationExample.java
@@ -23,13 +23,13 @@
 import org.apache.juneau.json.*;
 
 /**
- * TODO
+ * Json configuration example.
  */
 public class JsonConfigurationExample {
 
 	/**
-	 * TODO
-	 *
+	 * Examples on Json Serializers configured using properties
+	 * defined in JsonSerializer class
 	 * @param args
 	 * @throws Exception
 	 */
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/xml/XmlConfigurationExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/xml/XmlConfigurationExample.java
new file mode 100644
index 000000000..d8716fa4a
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/xml/XmlConfigurationExample.java
@@ -0,0 +1,66 @@
+// ***************************************************************************************************************************
+// * 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.juneau.examples.core.xml;
+
+import org.apache.juneau.examples.core.pojo.Pojo;
+import org.apache.juneau.examples.core.pojo.PojoComplex;
+import org.apache.juneau.xml.XmlSerializer;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Xml configuration example.
+ */
+public class XmlConfigurationExample {
+
+    /**
+     * Examples on XML Serializers configured using properties
+     * defined in XmlSerializer class.
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+
+        Pojo aPojo = new Pojo("a","<pojo>");
+
+        // Xml Serializers can be configured using properties defined in XmlSerializer.
+        String withWhitespace = XmlSerializer.create().ws().build().serialize(aPojo);
+        // the output will be padded with spaces after format characters.
+        System.out.println(withWhitespace);
+
+        HashMap<String, List<Pojo>> values = new HashMap<>();
+        PojoComplex pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values);
+
+        String mapescaped = XmlSerializer.create().trimEmptyMaps(true).build().serialize(pojoc);
+        // the output will have trimmed Empty maps.
+        System.out.println(mapescaped);
+
+        String nspaceToRoot = XmlSerializer.create().ns().addNamespaceUrisToRoot(true).build().serialize(aPojo);
+        // the output will add default name space to the xml document root.
+        System.out.println(nspaceToRoot);
+
+        Pojo nPojo = new Pojo("a",null);
+
+        String nullescaped = XmlSerializer.create().trimNullProperties(true).build().serialize(nPojo);
+        // the output will have trimmed null properties.
+        System.out.println(nullescaped);
+
+
+        String dNamsSpace = XmlSerializer.create().enableNamespaces(true).defaultNamespace("http://www.pierobon.org" +
+                "/iis/review1.htm.html#one").autoDetectNamespaces(true).addNamespaceUrisToRoot(true).build()
+                .serialize(aPojo);
+        // the output will have new default namespace added.
+        System.out.println(dNamsSpace);
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services