This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git
commit 1176a1d7e002d241b3143174e94cf1136ce83efd Author: Frank Vanderham <[email protected]> AuthorDate: Sun May 19 14:41:16 2019 -0600 Fix documentation for @JohnzonAny Fixed the documentation for @JohnzonAny by replacing the @Any annotations with @JohnzonAny and clarifying the mix between regular serialization and the use of @JohnzonAny. --- src/site/markdown/index.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index db026f0..58058c3 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -183,13 +183,19 @@ public class MyModel { #### @JohnzonAny -If you don't fully know you model but want to handle all keys you can use @JohnzonAny to capture/serialize them all: +If you don't fully know your model but want to handle all keys you can use @JohnzonAny to capture/serialize them all: <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>
