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

来源:互联网 发布:手机称重量软件 编辑:程序博客网 时间:2024/06/01 09:35

官方地址: 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 ValueSerializationDeserializationnameCustomize field nameemptyyesnoserializeInclude in serializationtrueyesnodeserializeInclude in deserializationtruenoyesformatFormat 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>

 

原创粉丝点击