Java Code Examples for com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition#getName()

The following examples show how to use com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition#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: AbstractOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 2
Source File: EntitySerializer.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 3
Source File: JacksonResourceSchemaProvider.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 4
Source File: JacksonValueMapper.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 5
Source File: ConfigTreeBuilder.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
private static String fullPath(final ConfigPath root, final BeanPropertyDefinition prop) {
    return (root == null ? "" : root.getPath() + ".") + prop.getName();
}