@Retention(value=CLASS)
@Target(value=METHOD)
public @interface PropertySpec
Mark on a method (could be cli command, or controller action) to specify the fields to be exported.
This annotation is only effective when there is one and only one type of object returned, as a single instance or a collection of instances, e.g
@PropertySpec({“firstName”,“lastName”,“email”}) public List<Employee> getEmployees(String search) { List<Employee> retList = EmployeeDao.find(search).asList(); return retList; }Suppose the request accept
application/json
type, then only the following field of the Employee
instances will be exported in JSON output: When the result is to be presented on a CliSession
and PropertySpec
annotation is presented, either TableView
or JsonView
can be used to define the presenting style. If both TableView
and JsonView
are found on the method then JsonView
is the winner. If non of them is presented then JsonView
will be used by default
When the result is to be write to an H.Response
, and PropertySpec
annotation is presented on the controller action method, then the return value (if not of type Result
) will be serialized into a JSON string and the filter will effect and impact the JSON string
TableView
,
JsonView
,
FastJsonPropertyPreFilter
Modifier and Type | Fields and Description |
---|---|
static java.lang.ThreadLocal<java.lang.String> |
current |
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String[] |
cli
Specify the spec for command line interface output
|
java.lang.String[] |
http
Specify the spec for http response output
|
java.lang.String[] |
value
Specify the object fields to be displayed in final result.
|
public abstract java.lang.String[] value
Specify the object fields to be displayed in final result. E.g.
@PropertySpec({“firstName”,“lastName”,“email”})You can specify multiple fields in one string, with fields separated with one of the following character:
,;:|
@PropertySpec(“firstName,lastName,email”)You can use
as
to specify the label, e.g. @PropertySpec(“fn as First name,ln as Last name,email as Email”)If there are multiple levels of objects, use
.
or /
to express the traverse path: @PropertySpec(“fn,ln,contact.address.street,contact.address.city,contact.email”)Instead of specifying fields to be exported, it can also specify the fields to be excluded from output with the symbol
-
, e.g. @PropertySpec(“-password,-salary”)when symbol
-
is used to specify the excluded fields, then all the fields without symbol -
in the list will be ignored. However it can still use as
notation to specify the label. E.g. @PropertySpec(“-password,-salary,fn as firstName,ln as lastName”)
Copyright © 2014–2017 ActFramework. All rights reserved.