com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition#getName ( )源码实例Demo

下面列出了com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected void extractAggregatedParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap,
    java.lang.reflect.Parameter methodParameter) {
  JavaType javaType = TypeFactory.defaultInstance().constructType(methodParameter.getParameterizedType());
  BeanDescription beanDescription = Json.mapper().getSerializationConfig().introspect(javaType);
  for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
    if (!propertyDefinition.couldSerialize()) {
      continue;
    }

    Annotation[] annotations = collectAnnotations(propertyDefinition);
    ParameterGenerator propertyParameterGenerator = new ParameterGenerator(method,
        methodAnnotationMap,
        propertyDefinition.getName(),
        annotations,
        propertyDefinition.getPrimaryType().getRawClass());
    parameterGenerators.add(propertyParameterGenerator);
  }
}
 
源代码2 项目: FROST-Server   文件: EntitySerializer.java
protected void serializeFieldCustomized(
        Entity entity,
        JsonGenerator gen,
        BeanPropertyDefinition property,
        List<BeanPropertyDefinition> properties,
        CustomSerialization annotation) throws IOException {
    // check if encoding field is present in current bean
    // get value
    // call CustomSerializationManager
    Optional<BeanPropertyDefinition> encodingProperty = properties.stream().filter(p -> p.getName().equals(annotation.encoding())).findFirst();
    if (!encodingProperty.isPresent()) {
        throw new JsonGenerationException("can not serialize instance of class '" + entity.getClass() + "'! \n"
                + "Reason: trying to use custom serialization for field '" + property.getName() + "' but field '" + annotation.encoding() + "' specifying enconding is not present!",
                gen);
    }
    Object value = encodingProperty.get().getAccessor().getValue(entity);
    String encodingType = null;
    if (value != null) {
        encodingType = value.toString();
    }
    String customJson = CustomSerializationManager.getInstance()
            .getSerializer(encodingType)
            .serialize(property.getAccessor().getValue(entity));
    if (customJson != null && !customJson.isEmpty()) {
        gen.writeFieldName(property.getName());
        gen.writeRawValue(customJson);
    }
}
 
@Override
public ResourceSchema getResourceSchema(TypeToken<?> type, ApiConfig config) {
  ResourceSchema schema = super.getResourceSchema(type, config);
  if (schema != null) {
    return schema;
  }
  ObjectMapper objectMapper =
      ObjectMapperUtil.createStandardObjectMapper(config.getSerializationConfig());
  JavaType javaType = objectMapper.getTypeFactory().constructType(type.getRawType());
  BeanDescription beanDescription = objectMapper.getSerializationConfig().introspect(javaType);
  ResourceSchema.Builder schemaBuilder = ResourceSchema.builderForType(type.getRawType());
  Set<String> genericDataFieldNames = getGenericDataFieldNames(type);
  for (BeanPropertyDefinition definition : beanDescription.findProperties()) {
    TypeToken<?> propertyType = getPropertyType(type, toMethod(definition.getGetter()),
        toMethod(definition.getSetter()), definition.getField(), config);
    String name = definition.getName();
    if (genericDataFieldNames == null || genericDataFieldNames.contains(name)) {
      if (hasUnresolvedType(propertyType)) {
        logger.atWarning().log("skipping field '%s' of type '%s' because it is unresolved.", name,
            propertyType);
        continue;
      }
      if (propertyType != null) {
        ResourcePropertySchema propertySchema = ResourcePropertySchema.of(propertyType);
        propertySchema.setDescription(definition.getMetadata().getDescription());
        schemaBuilder.addProperty(name, propertySchema);
      } else {
        logger.atWarning().log("No type found for property '%s' on class '%s'.", name, type);
      }
    } else {
      logger.atFine()
          .log("skipping field '%s' because it's not a Java client model field.", name);
    }
  }
  return schemaBuilder.build();
}
 
源代码4 项目: graphql-spqr   文件: JacksonValueMapper.java
private InputField toInputField(TypedElement element, BeanPropertyDefinition prop, ObjectMapper objectMapper, GlobalEnvironment environment) {
    AnnotatedType deserializableType = resolveDeserializableType(prop.getPrimaryMember(), element.getJavaType(), prop.getPrimaryType(), objectMapper);
    Object defaultValue = inputInfoGen.defaultValue(element.getElements(), element.getJavaType(), environment).orElse(null);
    return new InputField(prop.getName(), prop.getMetadata().getDescription(), element, deserializableType, defaultValue);
}
 
源代码5 项目: dropwizard-guicey   文件: ConfigTreeBuilder.java
private static String fullPath(final ConfigPath root, final BeanPropertyDefinition prop) {
    return (root == null ? "" : root.getPath() + ".") + prop.getName();
}