Ignore fields (set certain fields not to appear in json, or not to be provided when requested)
#Support for Jackson annotations
field.ignore=@com.fasterxml.jackson.annotation.JsonIgnore#value
#Support for Gson annotations
field.ignore=!@com.google.gson.annotations.Expose#serialize
TestJsonIgnoreBean.java
public class TestJsonIgnoreBean {
@Expose(serialize = true)
private Long shouldNotIgnoreForGson;
@Expose(serialize = false)
private Long shouldIgnoreForGson;
@JsonIgnore(false)
private Long shouldNotIgnoreForJackson;
@JsonIgnore
private Long shouldIgnoreForJackson;
//constructors...
//getters...
}
name | type | required | default | desc | other |
---|---|---|---|---|---|
shouldNotIgnoreForGson | integer | NO | mock: @natural(0,10000) | ||
shouldNotIgnoreForJackson | integer | NO | mock: @natural(0,10000) |
Ignore fields with specified names:
Configuration as follows
# ignore field 'log'
field.ignore=log
The following field will be ignored
private String log;
Ignore fields with specified types:
Configuration as follows
# ignore field 'log' typed xxx.xxx.Log
field.ignore=groovy:it.type().name()=="xxx.xxx.Log"
The following field will be ignored
private Log xxx;
Ignore fields with specified modifier
:
Configuration as follows
#ignore transient field
field.ignore=groovy:it.hasModifier("transient")||it.hasModifier("protected")
The following field will be ignored
private transient Int xxx;
protected Long yyy;