Java Code Examples for com.fasterxml.jackson.databind.ser.PropertyWriter#getName()

The following examples show how to use com.fasterxml.jackson.databind.ser.PropertyWriter#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonOutputFilter.java    From emissary with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer) throws Exception {

    String key = writer.getName();
    @SuppressWarnings("unchecked")
    Collection<Object> values = (Collection<Object>) ((Map<?, ?>) pojo).get(key);

    if (includeParameter(key)) {
        Collection<Object> write = filter(key, values);
        if (CollectionUtils.isNotEmpty(write)) {
            // customize the key
            jgen.writeFieldName(transform(key));

            // only write the element
            ((MapProperty) writer).setValue(write);
            writer.serializeAsElement(write, jgen, provider);
        }
    }
}
 
Example 2
Source File: BaseFilter.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer)
        throws Exception {
    String key = writer.getName();
    boolean prevDetails = details;

    // Check if we have to skip the field because it is marked as "details" and details is set to false
    // or if we have to turn details off temporarily in case the field is marked as "simple"
    JsonDetails det = writer.getAnnotation(JsonDetails.class);
    if (det != null) {
        if (!details && det.value()) {
            return;
        }

        if (det.simple()) {
            details = false;
        }
    }

    // Add our object to the path
    path.add(key);

    // Check if the permission service allows access to our path
    // If yes then we want to serialize the rest of our object
    if (permissionService.permits(perms, path)) {
        super.serializeAsField(pojo, jgen, provider, writer);
    }

    // Reset path and details after our object is done
    path.remove(key);
    details = prevDetails;
}
 
Example 3
Source File: TaggedLogAPIEntity.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider,
                             PropertyWriter writer)
    throws Exception {
    if (pojo instanceof TaggedLogAPIEntity) {
        TaggedLogAPIEntity entity = (TaggedLogAPIEntity)pojo;
        Set<String> modified = entity.modifiedQualifiers();
        Set<String> basePropertyNames = getPropertyNames();
        String writerName = writer.getName();
        if (modified.contains(writerName) || basePropertyNames.contains(writerName)) {
            if ((!entity.isSerializeVerbose() && verboseFields.contains(writerName))
                || (timestamp.equals(writerName)
                    && !EntityDefinitionManager.isTimeSeries(entity.getClass()))) {
                // log skip
                if (LOG.isDebugEnabled()) {
                    LOG.debug("skip field");
                }
            } else {
                // if serializeAlias is not null and exp is not null
                if (exp.equals(writerName) && entity.getSerializeAlias() != null
                    && entity.getExp() != null) {
                    Map<String, Object> _exp = new HashMap<String, Object>();
                    for (Map.Entry<String, Object> entry : entity.getExp().entrySet()) {
                        String alias = entity.getSerializeAlias().get(entry.getKey());
                        if (alias != null) {
                            _exp.put(alias, entry.getValue());
                        } else {
                            _exp.put(entry.getKey(), entry.getValue());
                        }
                    }
                    entity.setExp(_exp);
                }
                // write included field into serialized json output
                writer.serializeAsField(pojo, jgen, provider);
            }
        }
    } else {
        writer.serializeAsField(pojo, jgen, provider);
    }
}