Example usage for com.fasterxml.jackson.databind.ser BeanPropertyWriter getName

List of usage examples for com.fasterxml.jackson.databind.ser BeanPropertyWriter getName

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.ser BeanPropertyWriter getName.

Prototype

public String getName() 

Source Link

Usage

From source file:org.mongojack.internal.util.JacksonAccessor.java

public static BeanPropertyWriter findPropertyWriter(BeanSerializerBase serializer, String propertyName) {
    BeanPropertyWriter[] props = get(serializer, beanSerializerBaseProps, BeanPropertyWriter[].class);
    for (BeanPropertyWriter prop : props) {
        if (propertyName.equals(prop.getName())) {
            return prop;
        }/*  www .  j a v  a 2 s. co m*/
    }
    return null;
}

From source file:org.lightadmin.core.web.json.DynamicFilePropertyOmittingSerializerModifier.java

@Override
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc,
        BeanSerializerBuilder builder) {
    if (!configuration.isManagedDomainType(beanDesc.getBeanClass())) {
        return builder;
    }/*from   w  ww  .  j  a va2 s.  com*/

    PersistentEntity<?, ?> entity = configuration.forManagedDomainType(beanDesc.getBeanClass())
            .getPersistentEntity();

    List<BeanPropertyWriter> result = newArrayList();
    for (BeanPropertyWriter writer : builder.getProperties()) {
        PersistentProperty<?> persistentProperty = findProperty(writer.getName(), entity, beanDesc);

        if (persistentProperty == null) {
            result.add(writer);
            continue;
        }

        if (PersistentPropertyType.forPersistentProperty(persistentProperty) == FILE) {
            continue;
        }

        result.add(writer);
    }

    builder.setProperties(result);

    return builder;
}

From source file:org.craftercms.commons.jackson.mvc.GDataPropertyFilter.java

@Override
protected boolean include(final BeanPropertyWriter writer) {
    Class<?> clazz = writer.getMember().getDeclaringClass();
    String propName = writer.getName();
    if (!isPrimitive(clazz)) {
        propName = getMostSuperClassName(clazz) + "." + propName;
    }/*from w  w w.  ja  v a  2  s  . c o m*/
    checkForCrafterAnnotations(writer);
    return checkProperty(propName);
}

From source file:com.basho.riak.client.convert.RiakBeanSerializerModifier.java

/**
 * Checks if the property has any of the Riak annotations on it or the 
 * Jackson JsonProperty annotation. /*from   w  w  w .java 2  s.  c o  m*/
 * 
 * If a Riak annotation is present without the Jackson JsonProperty
 * annotation, this will return false.
 * 
 * If a property has been annotated with both the Jackson JsonProperty
 * annotation and a Riak annotation, the Jackson annotation takes precedent 
 * and this will return true.
 * 
 * @param beanPropertyWriter
 *            a {@link BeanPropertyWriter} to check for Riak* annotations
 * @return true if the property is not Riak annotated or is Jackson
* JsonProperty annotated, false otherwise
 */
private boolean keepProperty(BeanPropertyWriter beanPropertyWriter) {
    RiakKey key = null;
    RiakUsermeta usermeta = null;
    RiakLinks links = null;
    RiakIndex index = null;
    RiakVClock vclock = null;
    JsonProperty jacksonJsonProperty = null;
    RiakTombstone tombstone = null;

    AnnotatedMember member = beanPropertyWriter.getMember();
    if (member instanceof AnnotatedField) {
        AnnotatedElement element = member.getAnnotated();
        key = element.getAnnotation(RiakKey.class);
        usermeta = element.getAnnotation(RiakUsermeta.class);
        links = element.getAnnotation(RiakLinks.class);
        index = element.getAnnotation(RiakIndex.class);
        vclock = element.getAnnotation(RiakVClock.class);
        tombstone = element.getAnnotation(RiakTombstone.class);
        jacksonJsonProperty = element.getAnnotation(JsonProperty.class);
    } else {
        @SuppressWarnings("rawtypes")
        Class clazz = member.getDeclaringClass();
        Field field;
        try {
            field = clazz.getDeclaredField(beanPropertyWriter.getName());
            key = field.getAnnotation(RiakKey.class);
            usermeta = field.getAnnotation(RiakUsermeta.class);
            links = field.getAnnotation(RiakLinks.class);
            index = field.getAnnotation(RiakIndex.class);
            vclock = field.getAnnotation(RiakVClock.class);
            tombstone = field.getAnnotation(RiakTombstone.class);
            jacksonJsonProperty = field.getAnnotation(JsonProperty.class);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            // ignore, not a field means not a Riak annotated field.
        }
    }

    if (jacksonJsonProperty != null) {
        return true;
    } else {
        return key == null && usermeta == null && links == null && vclock == null && index == null
                && tombstone == null;
    }
}

From source file:org.gvnix.web.json.ConversionServiceBeanSerializerModifier.java

@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
        List<BeanPropertyWriter> beanProperties) {

    // We need the BeanPropertyDefinition to get the related Field
    List<BeanPropertyDefinition> properties = beanDesc.findProperties();
    Map<String, BeanPropertyDefinition> propertyDefMap = new HashMap<String, BeanPropertyDefinition>();
    for (BeanPropertyDefinition property : properties) {
        propertyDefMap.put(property.getName(), property);
    }//from  w  w  w. ja  v a2 s  .  c  o m

    // iterate over bean's properties to configure serializers
    for (int i = 0; i < beanProperties.size(); i++) {
        BeanPropertyWriter beanPropertyWriter = beanProperties.get(i);
        Class<?> propertyType = beanPropertyWriter.getPropertyType();

        if (beanPropertyWriter.hasSerializer()) {
            continue;
        }

        // For conversion between collection, array, and map types,
        // ConversionService.canConvert() method will return 'true'
        // but better to delegate in default Jackson property writer for
        // right start and ends markers serialization and iteration
        if (propertyType.isArray() || Collection.class.isAssignableFrom(propertyType)
                || Map.class.isAssignableFrom(propertyType)) {

            // Don't set ConversionService serializer, let Jackson
            // use default Collection serializer
            continue;
        } else if (BindingResult.class.isAssignableFrom(propertyType)) {
            // Use BindingResultSerializer
            beanPropertyWriter.assignSerializer(bindingResultSerializer);
        } else {

            // ConversionService uses value Class plus related Field
            // annotations to be able to select the right converter,
            // so we must get/ the Field annotations for success
            // formatting
            BeanPropertyDefinition propertyDef = propertyDefMap.get(beanPropertyWriter.getName());
            AnnotatedField annotatedField = propertyDef.getField();
            if (annotatedField == null) {
                continue;
            }
            AnnotatedElement annotatedEl = annotatedField.getAnnotated();

            // Field contains info about Annotations, info that
            // ConversionService uses for success formatting, use it if
            // available. Otherwise use the class of given value.
            TypeDescriptor sourceType = annotatedEl != null ? new TypeDescriptor((Field) annotatedEl)
                    : TypeDescriptor.valueOf(propertyType);

            TypeDescriptor targetType = TypeDescriptor.valueOf(String.class);
            if (beanPropertyWriter.getSerializationType() != null) {
                targetType = TypeDescriptor.valueOf(beanPropertyWriter.getSerializationType().getRawClass());
            }
            if (ObjectUtils.equals(sourceType, targetType)) {
                // No conversion needed
                continue;
            } else if (sourceType.getObjectType() == Object.class && targetType.getObjectType() == String.class
                    && beanPropertyWriter.getSerializationType() == null) {
                // Can't determine source type and no target type has been
                // configure. Delegate on jackson.
                continue;
            }

            // All other converters must be set in ConversionService
            if (this.conversionService.canConvert(sourceType, targetType)) {

                // We must create BeanPropertyWriter own Serializer that
                // has knowledge about the Field related to that
                // BeanPropertyWriter in order to have access to
                // Field Annotations for success serialization
                JsonSerializer<Object> jsonSerializer = new ConversionServicePropertySerializer(
                        this.conversionService, sourceType, targetType);

                beanPropertyWriter.assignSerializer(jsonSerializer);
            }
            // If no converter set, use default Jackson property writer
            else {
                continue;
            }
        }
    }
    return beanProperties;
}