com.fasterxml.jackson.databind.ser.PropertyWriter Java Examples

The following examples show how to use com.fasterxml.jackson.databind.ser.PropertyWriter. 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: JsonLogIgnoreFilter.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean include(PropertyWriter writer) {
    if (writer.findAnnotation(JsonLogIgnore.class) != null) {
        return false;
    }
    JsonLogIgnoreProperties jsonLogIgnoreProperties =
            writer.findAnnotation(JsonLogIgnoreProperties.class);
    if (jsonLogIgnoreProperties != null) {
        for (String ignoredName : jsonLogIgnoreProperties.value()) {
            if (Objects.equals(ignoredName, writer.getName())) {
                return false;
            }
        }
    }
    return super.include(writer);
}
 
Example #2
Source File: InternalConfigStateController.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Can serialize field?
 *
 * @param pojo the pojo
 * @param writer the writer
 * @return the boolean
 */
private boolean canSerializeField(final Object pojo, final PropertyWriter writer) {
    boolean foundPackage = false;
    final String packageName = pojo.getClass().getPackage().getName();
    for (int i = 0; !foundPackage && i < INCLUDE_PACKAGES.length; i++) {
        foundPackage = (packageName.startsWith(INCLUDE_PACKAGES[i]));
    }
    if (!foundPackage) {
        LOGGER.trace("Package [{}] is ignored", packageName);
        return false;
    }


    boolean foundField = true;
    final String fieldName = writer.getFullName().getSimpleName();
    for (int i = 0; foundField && i < EXCLUDE_FIELDS.length; i++) {
        foundField = !fieldName.equalsIgnoreCase(EXCLUDE_FIELDS[i]);
    }

    if (!foundField) {
        LOGGER.trace("Field [{}] is excluded", fieldName);
        return false;
    }
    return true;
}
 
Example #3
Source File: RntbdToken.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@Override
public void serializeAsField(
    final Object object,
    final JsonGenerator generator,
    final SerializerProvider provider,
    final PropertyWriter writer) throws Exception {

    if (generator.canOmitFields()) {

        final Object value = writer.getMember().getValue(object);

        if (value instanceof RntbdToken && !((RntbdToken) value).isPresent()) {
            return;
        }
    }

    writer.serializeAsField(object, generator, provider);
}
 
Example #4
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 #5
Source File: ApiPermissionFilter.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
private boolean includeField(Object pojo, PropertyWriter writer) {
//        if (writer.getAnnotation(ApiPermissionsAllowed.class)  == null) {
//            return true;
//        }
//
//        return Arrays.asList(writer.getAnnotation(ApiPermissionsAllowed.class).value())
//                .stream()
//                .anyMatch(apiPermission -> apiPermission.equals(((ApiEntity) pojo).getrgetPermission()));
        return true;
    }
 
Example #6
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 #7
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);
    }
}
 
Example #8
Source File: KatharsisFieldPropertyFilter.java    From katharsis-framework 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 (include(pojo, writer)) {
        super.serializeAsField(pojo, jgen, provider, writer);
    }
}
 
Example #9
Source File: CatalogEventFilter.java    From logging-log4j-audit 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 (writer.getName().equals("catalogId") && DEFAULT_CATALOG.equals(((Event)pojo).getCatalogId())) {
        return;
    }
    super.serializeAsField(pojo, jgen, provider, writer);
}
 
Example #10
Source File: JacksonObjectProvider.java    From ameba with MIT License 5 votes vote down vote up
@Override
public void serializeAsField(final Object pojo,
                             final JsonGenerator jgen,
                             final SerializerProvider prov,
                             final PropertyWriter writer) throws Exception {
    if (include(writer.getName())) {
        writer.serializeAsField(pojo, jgen, prov);
    }
}
 
Example #11
Source File: SentinelSecureFilter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private PropertyWriter filter(PropertyWriter writer) {
  if (!transform) {
    return writer;
  }

  SentinelSecure secure = writer.getAnnotation(SentinelSecure.class);
  if (secure == null || secure.value() == null || secure.value().isEmpty()) {
    return writer;
  }

  return new SensitivePropertyWriter((BeanPropertyWriter) writer, secure.value());
}
 
Example #12
Source File: JacksonObjectProvider.java    From ameba with MIT License 5 votes vote down vote up
@Override
public void serializeAsElement(final Object elementValue,
                               final JsonGenerator jgen,
                               final SerializerProvider prov,
                               final PropertyWriter writer) throws Exception {
    if (include(writer.getName())) {
        writer.serializeAsElement(elementValue, jgen, prov);
    }
}
 
Example #13
Source File: JacksonObjectProvider.java    From ameba with MIT License 5 votes vote down vote up
@Override
public void depositSchemaProperty(final PropertyWriter writer,
                                  final ObjectNode propertiesNode,
                                  final SerializerProvider provider) throws JsonMappingException {
    if (include(writer.getName())) {
        writer.depositSchemaProperty(propertiesNode, provider);
    }
}
 
Example #14
Source File: JacksonObjectProvider.java    From ameba with MIT License 5 votes vote down vote up
@Override
public void depositSchemaProperty(final PropertyWriter writer,
                                  final JsonObjectFormatVisitor objectVisitor,
                                  final SerializerProvider provider) throws JsonMappingException {
    if (include(writer.getName())) {
        writer.depositSchemaProperty(objectVisitor, provider);
    }
}
 
Example #15
Source File: InternalConfigStateController.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public void serializeAsField(final Object pojo, final JsonGenerator jgen,
                             final SerializerProvider provider,
                             final PropertyWriter writer) throws Exception {
    try {
        if (!canSerializeField(pojo, writer)) {
            return;
        }
        super.serializeAsField(pojo, jgen, provider, writer);
    } catch (final Exception e) {
        LOGGER.debug(e.getMessage());
    }
}
 
Example #16
Source File: FieldNamePropertyFilter.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean include(PropertyWriter writer) {
    return predicate.test(writer.getName());
}
 
Example #17
Source File: KatharsisFieldPropertyFilter.java    From katharsis-framework with Apache License 2.0 4 votes vote down vote up
public KatharsisFieldPropertyFilter(Predicate2<Object, PropertyWriter> includeChecker) {
    this.includeChecker = includeChecker;
}
 
Example #18
Source File: ApiPermissionFilter.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
@Override
public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer) throws Exception {
    if (includeField(pojo, writer)) {
        writer.serializeAsField(pojo, jgen, provider);
    }
}
 
Example #19
Source File: KatharsisFieldPropertyFilter.java    From katharsis-framework with Apache License 2.0 4 votes vote down vote up
private boolean include(Object bean, PropertyWriter writer) {
    return includeChecker.test(bean, writer);
}
 
Example #20
Source File: SentinelSecureFilter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void depositSchemaProperty(PropertyWriter writer, JsonObjectFormatVisitor objectVisitor, SerializerProvider provider) throws JsonMappingException {
  writer.depositSchemaProperty(objectVisitor, provider);
}
 
Example #21
Source File: SentinelSecureFilter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void depositSchemaProperty(PropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) throws JsonMappingException {
  writer.depositSchemaProperty(propertiesNode, provider);
}
 
Example #22
Source File: SentinelSecureFilter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void serializeAsElement(Object elementValue, JsonGenerator gen, SerializerProvider prov, PropertyWriter writer)
    throws Exception {
  filter(writer).serializeAsElement(elementValue, gen, prov);
}
 
Example #23
Source File: SentinelSecureFilter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void serializeAsField(Object pojo, JsonGenerator gen, SerializerProvider prov, PropertyWriter writer)
    throws Exception {
  filter(writer).serializeAsField(pojo, gen, prov);
}
 
Example #24
Source File: MixinFilter.java    From jfilter with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean include(PropertyWriter writer) {
    return !isFilterable(writer.getMember().getDeclaringClass(), writer.getName());
}
 
Example #25
Source File: JsonSerializer.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Accessor for iterating over logical properties that the type
 * handled by this serializer has, from serialization perspective.
 * Actual type of properties, if any, will be
 * {@link com.fasterxml.jackson.databind.ser.BeanPropertyWriter}.
 * Of standard Jackson serializers, only {@link com.fasterxml.jackson.databind.ser.BeanSerializer}
 * exposes properties.
 *
 * @since 2.6
 */
public Iterator<PropertyWriter> properties() {
    return ClassUtil.emptyIterator();
}