Example usage for com.fasterxml.jackson.databind BeanDescription findProperties

List of usage examples for com.fasterxml.jackson.databind BeanDescription findProperties

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind BeanDescription findProperties.

Prototype

public abstract List<BeanPropertyDefinition> findProperties();

Source Link

Usage

From source file:org.jddd.jackson.SimpleValueObjectSerializerModifier.java

private static List<BeanPropertyDefinition> getProperties(JavaType type, SerializationConfig config) {

    ClassIntrospector classIntrospector = config.getClassIntrospector();
    BeanDescription description = classIntrospector.forSerialization(config, type, config);

    return description.findProperties();
}

From source file:com.github.jonpeterson.jackson.module.versioning.VersionedModelUtils.java

public static BeanPropertyDefinition getSerializeToVersionProperty(BeanDescription beanDescription)
        throws RuntimeException {
    BeanPropertyDefinition serializeToVersionProperty = null;
    for (BeanPropertyDefinition definition : beanDescription.findProperties()) {

        // merge field and accessor annotations
        if (definition instanceof POJOPropertyBuilder)
            ((POJOPropertyBuilder) definition).mergeAnnotations(true);

        AnnotatedMember accessor = definition.getAccessor();
        if (accessor != null && accessor.hasAnnotation(JsonSerializeToVersion.class)) {
            if (serializeToVersionProperty != null)
                throw new RuntimeException("@" + JsonSerializeToVersion.class.getSimpleName()
                        + " must be present on at most one field or method");
            if (accessor.getRawType() != String.class
                    || (definition.getField() == null && !definition.hasGetter()))
                throw new RuntimeException("@" + JsonSerializeToVersion.class.getSimpleName()
                        + " must be on a field or a getter method that returns a String");
            serializeToVersionProperty = definition;
        }/*w  w  w .  j  av a2s.c  o  m*/
    }

    return serializeToVersionProperty;
}

From source file:org.usrz.libs.riak.introspection.RiakEntityWriter.java

    private final KeySeri

protected RiakEntityWriter(BeanDescription description) {
    this.description = description;

    for (BeanPropertyDefinition property: description.findProperties()) {
        if (property.couldSerialize()) {

        }//from  www  .  j a va 2  s .  c  o  m
        System.err.println(property);
    }
}

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

private PersistentProperty<?> findProperty(String finalName, PersistentEntity<?, ?> entity,
        BeanDescription description) {
    for (BeanPropertyDefinition definition : description.findProperties()) {
        if (definition.getName().equals(finalName)) {
            return entity.getPersistentProperty(definition.getInternalName());
        }/*from w  w w. j av a  2 s  . c o m*/
    }
    return null;
}

From source file:com.github.nmorel.gwtjackson.jackson.mixins.MixinSerForMethodsJacksonTest.java

@Test
public void testIntermediateMixin() {
    objectMapper.addMixIn(BaseClass.class, MixIn.class);

    JavaType type = objectMapper.getTypeFactory().constructType(LeafClass.class);
    BeanDescription desc = objectMapper.getSerializationConfig().introspect(type);
    List<BeanPropertyDefinition> props = desc.findProperties();

    MixinSerForMethodsTester.INSTANCE.testIntermediateMixin(createWriter(LeafClass.class));
}

From source file:com.addthis.codec.jackson.WriteonlyPropertyIgnorer.java

@Override
public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser jp,
        JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName)
        throws IOException, JsonProcessingException {
    ObjectCodec objectCodec = jp.getCodec();
    if (objectCodec instanceof ObjectMapper) {
        ObjectMapper objectMapper = (ObjectMapper) objectCodec;
        BeanDescription beanDescription = objectMapper.getSerializationConfig()
                .introspect(ctxt.constructType(beanOrClass.getClass()));
        for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
            if (propertyName.equals(propertyDefinition.getName())) {
                jp.skipChildren();/*from www . j  a v a 2s. c  o m*/
                return true;
            }
        }
    }
    return false;
}

From source file:springfox.documentation.schema.property.field.FieldModelPropertyProvider.java

@Override
public List<ModelProperty> propertiesFor(ResolvedType type, ModelContext givenContext) {

    List<ModelProperty> serializationCandidates = newArrayList();
    BeanDescription beanDescription = beanDescription(type, givenContext);
    Map<String, BeanPropertyDefinition> propertyLookup = Maps.uniqueIndex(beanDescription.findProperties(),
            BeanPropertyDefinitions.beanPropertyByInternalName());

    for (ResolvedField childField : fieldProvider.in(type)) {
        if (propertyLookup.containsKey(childField.getName())) {
            BeanPropertyDefinition propertyDefinition = propertyLookup.get(childField.getName());
            Optional<BeanPropertyDefinition> jacksonProperty = BeanPropertyDefinitions
                    .jacksonPropertyWithSameInternalName(beanDescription, propertyDefinition);
            AnnotatedMember member = propertyDefinition.getPrimaryMember();
            serializationCandidates.addAll(newArrayList(
                    addSerializationCandidates(member, childField, jacksonProperty, givenContext)));
        }// w  w w.  j  a  v a2  s.  co m
    }
    return serializationCandidates;
}

From source file:org.springframework.data.rest.webmvc.json.JacksonMetadata.java

/**
 * Creates a new {@link JacksonMetadata} instance for the given {@link ObjectMapper} and type.
 * //from w w w.j a v a 2 s. c  o  m
 * @param mapper must not be {@literal null}.
 * @param type must not be {@literal null}.
 */
public JacksonMetadata(ObjectMapper mapper, Class<?> type) {

    Assert.notNull(mapper, "ObjectMapper must not be null!");
    Assert.notNull(type, "Type must not be null!");

    this.mapper = mapper;

    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    JavaType javaType = serializationConfig.constructType(type);
    BeanDescription description = serializationConfig.introspect(javaType);

    this.definitions = description.findProperties();
    this.isValue = description.findJsonValueMethod() != null;

    DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
    JavaType deserializationType = deserializationConfig.constructType(type);

    this.deserializationDefinitions = deserializationConfig.introspect(deserializationType).findProperties();
}

From source file:springfox.documentation.schema.property.bean.BeanModelPropertyProvider.java

@Override
public List<ModelProperty> propertiesFor(ResolvedType type, ModelContext givenContext) {

    List<ModelProperty> serializationCandidates = newArrayList();
    BeanDescription beanDescription = beanDescription(type, givenContext);
    Map<String, BeanPropertyDefinition> propertyLookup = uniqueIndex(beanDescription.findProperties(),
            BeanPropertyDefinitions.beanPropertyByInternalName());
    for (Map.Entry<String, BeanPropertyDefinition> each : propertyLookup.entrySet()) {

        BeanPropertyDefinition propertyDefinition = each.getValue();
        Optional<BeanPropertyDefinition> jacksonProperty = jacksonPropertyWithSameInternalName(beanDescription,
                propertyDefinition);//from w  w  w. j a  v  a2s.  c  o  m
        AnnotatedMember member = propertyDefinition.getPrimaryMember();
        Optional<ResolvedMethod> accessor = findAccessorMethod(type, each.getKey(), member);
        if (accessor.isPresent()) {
            serializationCandidates
                    .addAll(addCandidateProperties(member, accessor.get(), jacksonProperty, givenContext));
        }
    }
    return serializationCandidates;
}

From source file:gaffer.rest.service.SimpleGraphConfigurationService.java

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override/*from   ww w .  ja v  a 2 s .  c o m*/
public Set<String> getSerialisedFields(final String className) {
    final Class<?> clazz;
    try {
        clazz = Class.forName(className);
    } catch (Exception e) {
        throw new IllegalArgumentException("Class name was not recognised: " + className, e);
    }

    final ObjectMapper mapper = new ObjectMapper();
    final JavaType type = mapper.getTypeFactory().constructType(clazz);
    final BeanDescription introspection = mapper.getSerializationConfig().introspect(type);
    final List<BeanPropertyDefinition> properties = introspection.findProperties();

    final Set<String> fields = new HashSet<>();
    for (final BeanPropertyDefinition property : properties) {
        fields.add(property.getName());
    }

    return fields;
}