use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project dhis2-core by dhis2.
the class FieldFilterService method toObjectNodes.
public List<ObjectNode> toObjectNodes(FieldFilterParams<?> params) {
List<ObjectNode> objectNodes = new ArrayList<>();
if (params.getObjects().isEmpty()) {
return objectNodes;
}
List<FieldPath> fieldPaths = FieldFilterParser.parse(params.getFilters());
// In case we get a proxied object in we can't just use o.getClass(), we
// need to figure out the real class name by using HibernateProxyUtils.
Object firstObject = params.getObjects().iterator().next();
fieldPathHelper.apply(fieldPaths, HibernateProxyUtils.getRealClass(firstObject));
SimpleFilterProvider filterProvider = getSimpleFilterProvider(fieldPaths, params.isSkipSharing());
// only set filter provider on a local copy so that we don't affect
// other object mappers (running across other threads)
ObjectMapper objectMapper = jsonMapper.copy().setFilterProvider(filterProvider);
Map<String, List<FieldTransformer>> fieldTransformers = getTransformers(fieldPaths);
for (Object object : params.getObjects()) {
ObjectNode objectNode = objectMapper.valueToTree(object);
applyTransformers(objectNode, null, "", fieldTransformers);
objectNodes.add(objectNode);
}
return objectNodes;
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project knox by apache.
the class KnoxShellTableJSONSerializer method saveTableInFile.
private static String saveTableInFile(KnoxShellTable table, boolean data, String filePath) {
try {
final String jsonResult;
if (data) {
final SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter("knoxShellTableFilter", SimpleBeanPropertyFilter.filterOutAllExcept("headers", "rows", "title", "id"));
jsonResult = JsonUtils.renderAsJsonString(table, filterProvider, JSON_DATE_FORMAT.get());
} else {
jsonResult = JsonUtils.renderAsJsonString(KnoxShellTableCallHistory.getInstance().getCallHistory(table.id), null, JSON_DATE_FORMAT.get());
}
KnoxShellTableFileUtils.persistToFile(filePath, jsonResult);
return "Successfully saved into " + filePath;
} catch (IOException e) {
throw new KnoxShellException("Error while saving KnoxShellTable JSON into " + filePath, e);
}
}
Aggregations