public class FieldFilter extends Object
The filter will keep only the fields specified. Fields are comma delimited and nested fields can be referenced by their hierarchical field address. This is exemplified by the following:
id,name,inner_model/name,inner_model2/embedded_inner/id,list_model/id
This will result in producing the following json:
{ "id": "id1", "name": "name1", "inner_model" : { "name" : "inner_name1" }, "inner_model2" : { "embedded_inner" : { "id" : "embedded_id1" } }, "list_model" : [ { "id" : "elem1" }, { "id" : "elem2" } ] }
Using the above example, if you want filtering to be provided for embedded_inner, you'd need to provide the string:
inner_model2/embedded_inner
This would serialize the entire object for key "inner_model2"/"embedded_inner".
Note: json fields containing a '/' character are NOT supported by this filter at this time.
Modifier and Type | Field and Description |
---|---|
static FieldFilter |
UNFILTERED_FIELD |
Modifier and Type | Method and Description |
---|---|
protected void |
addField(String field)
Adds a field to be filtered for this FieldFilter.
|
static FieldFilter |
create(String fieldParam)
Creates a new
FieldFilter to handle empty or null params. |
protected Map<String,FieldFilter> |
getFilters() |
boolean |
hasFilters()
Returns true if this FieldFilter contains filters, false otherwise.
|
void |
writeJson(com.fasterxml.jackson.core.JsonParser parser,
com.fasterxml.jackson.core.JsonGenerator jgen)
Writes the json from the parser onto the generator, using the filters to only write the objects
specified.
|
public static final FieldFilter UNFILTERED_FIELD
public static FieldFilter create(String fieldParam)
FieldFilter
to handle empty or null params.fieldParam
- comma separated list of fields to keep when executing the filter; should be
in the format"id,inner_model/id,other_thing" corresponding to field names in the JSONprotected void addField(String field)
public boolean hasFilters()
protected Map<String,FieldFilter> getFilters()
public void writeJson(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.core.JsonGenerator jgen) throws IOException
parser
- JsonParser that is created from a Jackson utility (i.e. ObjectMapper)jgen
- JsonGenerator that is used for writing json onto an underlying streamcom.fasterxml.jackson.core.JsonGenerationException
- exception if Jackson throws an error while iterating through
the JsonParserIOException
- if en error occurs while Jackson is parsing or writing jsonCopyright © 2020 Cerner Innovation, Inc.. All rights reserved.