blob: db66e6b64b3b7458b23e7973fdcba0678ba5ab9d [file] [log] [blame]
<!--
/***************************************************************************************************************************
* 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.
***************************************************************************************************************************/
-->
@Json Annotation
<p>
The {@link oaj.json.annotation.Json @Json} annotation
is used to override the behavior of {@link oaj.json.JsonSerializer} on individual bean classes or properties.
</p>
<p>
The annotation can be applied to beans as well as other objects serialized to other types (e.g. strings).
</p>
<ul class='javatree'>
<li class='ja'>{@link oaj.json.annotation.Json}
<ul>
<li class='jf'>{@link oaj.json.annotation.Json#wrapperAttr() wrapperAttr}
</ul>
</ul>
<p>
The {@link oaj.json.annotation.Json#wrapperAttr() @Json(wrapperAttr)} annotation
can be used to wrap beans inside a JSON object with a specified attribute name.
</p>
<h5 class='figure'>Example:</h5>
<p class='bpcode w800'>
<ja>@Json</ja>(wrapperAttr=<js>"personBean"</js>)
<jk>public class</jk> Person {
<jk>public</jk> String <jf>name</jf> = <js>"John Smith"</js>;
}
</p>
<p>
The following shows the JSON representation with and without the annotation present:
</p>
<table class='styled w800'>
<tr>
<th>Without annotation</th>
<th>With annotation</th>
</tr>
<tr>
<td class='code'>
{
<jok>name</jok>: <jov>'John Smith'</jov>
}
</td>
<td class='code'>
{
<jok>personBean</jok>: {
<jok>name</jok>: <jov>'John Smith'</jov>
}
}
</td>
</tr>
</table>