您的位置:首页 > 编程语言 > Java开发

struts json result 指定需要序列化的属性

2012-06-10 16:07 330 查看
官方地址: http://struts.apache.org/2.2.3/docs/json-plugin.html

设置哪些属性要序列化哪些不需要序列化;

Customizing Serialization and Deserialization

Use the JSON annotation to customize the serialization/deserialization process. Available JSON annotation fields:

NameDescriptionDefault ValueSerializationDeserialization
nameCustomize field nameemptyyesno
serializeInclude in serializationtrueyesno
deserializeInclude in deserializationtruenoyes
formatFormat used to format/parse a Date field"yyyy-MM-dd'T'HH:mm:ss"yesyes

Excluding properties

A comma-delimited list of regular expressions can be passed to the JSON Result and Interceptor, properties matching any of these regular expressions will be ignored on the serialization process:

<!-- Result fragment -->
<result type="json">
<param name="excludeProperties">
login.password,
studentList.*\.sin
</param>
</result>

<!-- Interceptor fragment -->
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<param name="excludeProperties">
login.password,
studentList.*\.sin
</param>
</interceptor-ref>


Including properties

A comma-delimited list of regular expressions can be passed to the JSON Result to restrict which properties will be serialized. ONLY properties matching any of these regular expressions will be included in the serialized output.


Note

Exclude property expressions take precedence over include property expressions. That is, if you use include and exclude property expressions on the same result, include property expressions will not be applied if an exclude exclude property expression matches
a property first.
<!-- Result fragment -->
<result type="json">
<param name="includeProperties">
^entries\[\d+\]\.clientNumber,
^entries\[\d+\]\.scheduleNumber,
^entries\[\d+\]\.createUserId
</param>
</result>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: