johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frank Vanderham <twelve.eig...@gmail.com>
Subject Re: How to patch the documentation for @JohnzonAny?
Date Sun, 19 May 2019 18:02:01 GMT
I wasn't sure if the mailing list supports attachments or not, so I'll
put the patch inline in the text below. Let me know if it's easier for
me to just attach a .patch file.

Of course, also please review the patch for correctness. I'm open to
suggestions.

==========
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index db026f0..37cee75 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -187,9 +187,15 @@ If you don't fully know you model but want to
handle all keys you can use @Johnz

 <pre class="prettyprint linenums"><![CDATA[
 public class AnyMe {
-    @JohnzonAny // ignore normal serialization of this field
-    private String name; // known
-    private Map<String, Object> any = new TreeMap<String, Object>(); // unknown
+    private String name; // Regular serialization for the known 'name' field
+
+    /* This example uses a TreeMap to store and retrieve the other unknown
+       fields for the @JohnzonAny annotated methods, but you can choose
+       anything you want. Use @JohnzonIgnore to avoid exposing this as
+       an actual 'unknownFields' property in JSON.
+    */
+    @JohnzonIgnore
+    private Map<String, Object> unknownFields = new TreeMap<String, Object>();

     public String getName() {
         return name;
@@ -199,14 +205,14 @@ public class AnyMe {
         this.name = name;
     }

-    @Any
+    @JohnzonAny
     public Map<String, Object> getAny() {
-        return any;
+        return unknownFields;
     }

-    @Any
+    @JohnzonAny
     public void handle(final String key, final Object val) {
-        any.put(key, val);
+        this.unknownFields.put(key, val);
     }
 }
 ]]></pre>
==========

Mime
View raw message