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/10 18:37:35 UTC

[GitHub] jamesbognar closed pull request #31: Adding html serialize sample and doc tweaks

jamesbognar closed pull request #31: Adding html serialize sample and doc tweaks
URL: https://github.com/apache/juneau/pull/31
 
 
   

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/14.juneau-examples-core/01.Examples.html b/juneau-doc/docs/Topics/14.juneau-examples-core/01.Examples.html
index a4f5bf62f..5a421d5b6 100644
--- a/juneau-doc/docs/Topics/14.juneau-examples-core/01.Examples.html
+++ b/juneau-doc/docs/Topics/14.juneau-examples-core/01.Examples.html
@@ -35,4 +35,9 @@
 		<li class='jc'>{@link oaj.examples.core.rdf.RdfExample} - RdfXmlSerializer usage on serialize simple Pojo bean.
 		<li class='jc'>{@link oaj.examples.core.rdf.RdfComplexExample} - RdfXmlSerializer usage on serialize complex Pojo bean.
 	</ul>
+	<li class='jp'><code>org.apache.juneau.examples.core.html</code>
+		<ul>
+			<li class='jc'>{@link oaj.examples.core.core.HtmlSimpleExample} - Htmlerializer usage on serialize simple Pojo bean.
+			<li class='jc'>{@link oaj.examples.core.core.HtmlCompexExample} - HtmlSerializer usage on serialize complex Pojo bean.
+		</ul>
 </ul>
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlComplexExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlComplexExample.java
new file mode 100644
index 000000000..ecc57cc88
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlComplexExample.java
@@ -0,0 +1,69 @@
+// ***************************************************************************************************************************
+// * 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.html;
+
+import org.apache.juneau.examples.core.pojo.Pojo;
+import org.apache.juneau.examples.core.pojo.PojoComplex;
+import org.apache.juneau.html.HtmlSerializer;
+import org.apache.juneau.html.HtmlParser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Sample class which shows the complex usage of HtmlSerializer and HtmlParser.
+ */
+public class HtmlComplexExample {
+
+    /**
+     * Serializing PojoComplex bean into Html type
+     * and Deserialize back to PojoComplex instance type.
+     *
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        // Juneau provides static constants with the most commonly used configurations
+        // Get a reference to a serializer - converting POJO to flat format
+        HtmlSerializer htmlSerializer = HtmlSerializer.DEFAULT;
+        // Get a reference to a parser - converts that flat format back into the POJO
+        HtmlParser htmlParser = HtmlParser.DEFAULT;
+
+        // Fill some data to a PojoComplex bean
+        HashMap<String, List<Pojo>> values = new HashMap<>();
+        ArrayList<Pojo> setOne = new ArrayList<>();
+        setOne.add(new Pojo("1.1", "name1"));
+        setOne.add(new Pojo("1.1", "name2"));
+        ArrayList<Pojo> setTwo = new ArrayList<>();
+        setTwo.add(new Pojo("1.2", "name1"));
+        setTwo.add(new Pojo("1.2", "name2"));
+        values.put("setOne", setOne);
+        values.put("setTwo", setTwo);
+        PojoComplex pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values);
+
+        String flat = htmlSerializer.serialize(pojoc);
+
+        // Print out the created POJO in JSON format.
+        System.out.println(flat);
+
+        PojoComplex parse = htmlParser.parse(flat, PojoComplex.class);
+
+        assert parse.getId().equals(pojoc.getId());
+        assert parse.getInnerPojo().getName().equals(pojoc.getInnerPojo().getName());
+        assert parse.getInnerPojo().getId().equals(pojoc.getInnerPojo().getId());
+
+        // The object above can be parsed thanks to the @BeanConstructor(properties = id,name) annotation on Pojo
+        // Using this approach, you can keep your POJOs immutable, and still serialize and deserialize them.
+    }
+}
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlSimpleExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlSimpleExample.java
new file mode 100644
index 000000000..6f8abd10c
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/HtmlSimpleExample.java
@@ -0,0 +1,51 @@
+// ***************************************************************************************************************************
+// * 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.html;
+
+import org.apache.juneau.examples.core.pojo.Pojo;
+import org.apache.juneau.html.HtmlParser;
+import org.apache.juneau.html.HtmlSerializer;
+
+/**
+ * Sample class which shows the simple usage of HtmlSerializer and HtmlParser.
+ */
+public class HtmlSimpleExample {
+    /**
+     * Serializing Pojo bean into Html format
+     * and Deserialize back to Pojo instance type.
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception{
+        // Juneau provides static constants with the most commonly used configurations
+        // Get a reference to a serializer - converting POJO to flat format
+        HtmlSerializer htmlSerializer = HtmlSerializer.DEFAULT;
+        // Get a reference to a parser - converts that flat format back into the POJO
+        HtmlParser htmlParser = HtmlParser.DEFAULT;
+
+        Pojo pojo = new Pojo("id","name");
+
+        String flat = htmlSerializer.serialize(pojo);
+
+        // Print out the created POJO in JSON format.
+        System.out.println(flat);
+
+        Pojo parse = htmlParser.parse(flat, Pojo.class);
+
+        assert parse.getId().equals(pojo.getId());
+        assert parse.getName().equals(pojo.getName());
+
+        // The object above can be parsed thanks to the @BeanConstructor(properties = id,name) annotation on Pojo
+        // Using this approach, you can keep your POJOs immutable, and still serialize and deserialize them.
+    }
+}
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/package-info.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/package-info.java
new file mode 100755
index 000000000..f579cd240
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/html/package-info.java
@@ -0,0 +1,18 @@
+// ***************************************************************************************************************************
+// * 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.                                              *
+// ***************************************************************************************************************************
+
+/**
+ * Examples
+ */
+package org.apache.juneau.examples.core.html;
+
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonComplexExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonComplexExample.java
index 0cb2846cd..08530490d 100644
--- a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonComplexExample.java
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonComplexExample.java
@@ -21,7 +21,7 @@
 import java.util.List;
 
 /**
- * Sample class which shows the complex usage of JsonSerializer.
+ * Sample class which shows the complex usage of JsonSerializer and JsonParser.
  */
 public class JsonComplexExample {
     /**
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonSimpleExample.java b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonSimpleExample.java
index be90efd12..d2b8a8dcd 100644
--- a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonSimpleExample.java
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/json/JsonSimpleExample.java
@@ -24,7 +24,7 @@
 import org.apache.juneau.json.JsonSerializer;
 
 /**
- * TODO
+ * Sample class which shows the simple usage of JsonSerializer and JsonParser.
  */
 public class JsonSimpleExample {
 


 

----------------------------------------------------------------
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