Search in sources :

Example 51 with SimpleFilterProvider

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;
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with SimpleFilterProvider

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);
    }
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) IOException(java.io.IOException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException)

Aggregations

SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)52 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)17 PropertyFilter (com.fasterxml.jackson.databind.ser.PropertyFilter)12 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)11 Test (org.junit.Test)10 ApiPermissionFilter (io.gravitee.management.service.jackson.filter.ApiPermissionFilter)9 Before (org.junit.Before)9 Test (org.junit.jupiter.api.Test)7 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)6 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 HashSet (java.util.HashSet)4 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)3 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)3 IOException (java.io.IOException)3 lombok.val (lombok.val)3 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)3 AuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AuthenticationProperties)3 LdapAuthenticationProperties (org.apereo.cas.configuration.model.support.ldap.LdapAuthenticationProperties)3