当前位置: 首页>>代码示例>>Java>>正文


Java BeanDescription.findProperties方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.BeanDescription.findProperties方法的典型用法代码示例。如果您正苦于以下问题:Java BeanDescription.findProperties方法的具体用法?Java BeanDescription.findProperties怎么用?Java BeanDescription.findProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.BeanDescription的用法示例。


在下文中一共展示了BeanDescription.findProperties方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSerialisedFields

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<String> getSerialisedFields(final String className) {
    final Class<?> clazz;
    try {
        clazz = Class.forName(className);
    } catch (final 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;
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:23,代码来源:GraphConfigurationService.java

示例2: getSerialisedFields

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Response getSerialisedFields(final String className) {
    final Class<?> clazz;
    try {
        clazz = Class.forName(className);
    } catch (final 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 Response.ok(fields)
                   .header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE)
                   .build();
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:26,代码来源:GraphConfigurationServiceV2.java

示例3: getResourceSchema

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
@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.warning("skipping field '" + name + "' of type '" + propertyType
            + "' because it is unresolved.");
        continue;
      }
      if (propertyType != null) {
        schemaBuilder.addProperty(name, ResourcePropertySchema.of(propertyType));
      } else {
        logger.warning("No type found for property '" + name + "' on class '" + type + "'.");
      }
    } else {
      logger.fine("skipping field '" + name + "' because it's not a Java client model field.");
    }
  }
  return schemaBuilder.build();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:34,代码来源:JacksonResourceSchemaProvider.java

示例4: findBeanProperties

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider paramSerializerProvider, BeanDescription paramBeanDescription, BeanSerializerBuilder paramBeanSerializerBuilder)
{
  List localList = paramBeanDescription.findProperties();
  SerializationConfig localSerializationConfig = paramSerializerProvider.getConfig();
  removeIgnorableTypes(localSerializationConfig, paramBeanDescription, localList);
  if (localSerializationConfig.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS))
    removeSetterlessGetters(localSerializationConfig, paramBeanDescription, localList);
  if (localList.isEmpty())
    return null;
  boolean bool = usesStaticTyping(localSerializationConfig, paramBeanDescription, null);
  PropertyBuilder localPropertyBuilder = constructPropertyBuilder(localSerializationConfig, paramBeanDescription);
  ArrayList localArrayList = new ArrayList(localList.size());
  TypeBindings localTypeBindings = paramBeanDescription.bindingsForBeanType();
  Iterator localIterator = localList.iterator();
  while (localIterator.hasNext())
  {
    BeanPropertyDefinition localBeanPropertyDefinition = (BeanPropertyDefinition)localIterator.next();
    AnnotatedMember localAnnotatedMember = localBeanPropertyDefinition.getAccessor();
    if (localBeanPropertyDefinition.isTypeId())
    {
      if (localAnnotatedMember != null)
      {
        if (localSerializationConfig.canOverrideAccessModifiers())
          localAnnotatedMember.fixAccess();
        paramBeanSerializerBuilder.setTypeId(localAnnotatedMember);
      }
    }
    else
    {
      AnnotationIntrospector.ReferenceProperty localReferenceProperty = localBeanPropertyDefinition.findReferenceType();
      if ((localReferenceProperty == null) || (!localReferenceProperty.isBackReference()))
        if ((localAnnotatedMember instanceof AnnotatedMethod))
          localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedMethod)localAnnotatedMember));
        else
          localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedField)localAnnotatedMember));
    }
  }
  return localArrayList;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:40,代码来源:BeanSerializerFactory.java

示例5: serialize

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void serialize(ExecutionResult value, JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonGenerationException
{
    
    SerializationConfig config = provider.getConfig();
    Object rootObj = value.getRoot();
    if (rootObj == null)
    {
        provider.getDefaultNullValueSerializer().serialize(null, jgen, provider);
    }
    else
    {
        Class<?> cls = rootObj.getClass();
        Map toBeSerialized = new HashMap(); //create an untyped map, add the contents of the root + the embeds.
        BeanPropertiesFilter filter = value.getFilter();
        if (filter == null) filter = BeanPropertiesFilter.ALLOW_ALL;
        
        if (Map.class.isAssignableFrom(cls))
        {
            // Its a map so 
            Map rootAsaMap = (Map) rootObj;
            toBeSerialized.putAll(rootAsaMap);
        }
        else
        {
            JavaType classType = config.constructType(cls);
            BeanDescription beanDesc = provider.getConfig().introspect(classType);
            List<BeanPropertyDefinition> props = beanDesc.findProperties();
            for (BeanPropertyDefinition beanProperty : props)
            {
                if (beanProperty.couldSerialize() && filter.isAllowed(beanProperty.getName()))
                {
                    Object propertyValue = ResourceInspectorUtil.invokeMethod(beanProperty.getGetter().getAnnotated(), rootObj);
                    if (propertyValue != null)
                    {
                        if((propertyValue instanceof String))
                        {
                        	if(((String)propertyValue).trim().length() > 0)
                        	{
                        		toBeSerialized.put(beanProperty.getName(), propertyValue);
                        	}
                        }
                        else
                        {
                        	toBeSerialized.put(beanProperty.getName(), propertyValue);
                        }
                    }
                }
            }
        }
        
        //Add embedded
        for (Entry<String, Object> embedded : value.getEmbedded().entrySet())
        {
            if (filter == null || filter.isAllowed(embedded.getKey()))
            {
              toBeSerialized.put(embedded.getKey(),embedded.getValue());
            }
        }

        //if its an embedded entity then render the properties (not as an "entry:")
        if (value.isAnEmbeddedEntity())
        {
            jgen.writeObject(toBeSerialized);
        }
        else
        {
            jgen.writeStartObject();
            jgen.writeObjectField("entry", toBeSerialized);
            if (value.getRelated() != null && !value.getRelated().isEmpty())
            {
              jgen.writeObjectField("relations", value.getRelated());
            }
            jgen.writeEndObject();
        }

    }

}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:82,代码来源:SerializerOfExecutionResult.java

示例6: deserialize

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
@Override
public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    Entity result;
    try {
        result = clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
        throw new IOException("Error deserializing JSON!");
    }
    // need to make subclass of this class for every Entity subclass with custom field to get expected class!!!
    BeanDescription beanDescription = ctxt.getConfig().introspect(ctxt.constructType(clazz));
    ObjectMapper mapper = (ObjectMapper) parser.getCodec();
    JsonNode obj = (JsonNode) mapper.readTree(parser);
    List<BeanPropertyDefinition> properties = beanDescription.findProperties();
    Iterator<Map.Entry<String, JsonNode>> i = obj.fields();

    // First check if we know all properties that are present.
    if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
        for (; i.hasNext();) {
            Map.Entry<String, JsonNode> next = i.next();
            String fieldName = next.getKey();
            JsonNode field = next.getValue();
            Optional<BeanPropertyDefinition> findFirst = properties.stream().filter(p -> p.getName().equals(fieldName)).findFirst();
            if (!findFirst.isPresent()) {
                throw new UnrecognizedPropertyException(parser, "Unknown field: " + fieldName, parser.getCurrentLocation(), clazz, fieldName, null);
            }
        }
    }

    for (BeanPropertyDefinition classProperty : properties) {
        if (obj.has(classProperty.getName())) {
            // property is present in class and json
            Annotation annotation = classProperty.getAccessor().getAnnotation(CustomSerialization.class);
            if (annotation != null) {
                // property has custom annotation
                // check if encoding property is also present in json (and also in class itself for sanity reasons)
                CustomSerialization customAnnotation = (CustomSerialization) annotation;
                Optional<BeanPropertyDefinition> encodingClassProperty = properties.stream().filter(p -> p.getName().equals(customAnnotation.encoding())).findFirst();
                if (!encodingClassProperty.isPresent()) {
                    throw new IOException("Error deserializing JSON as class '" + clazz.toString() + "' \n"
                            + "Reason: field '" + customAnnotation.encoding() + "' specified by annotation as encoding field is not defined in class!");
                }
                String customEncoding = null;
                if (obj.has(customAnnotation.encoding())) {
                    customEncoding = obj.get(customAnnotation.encoding()).asText();
                }
                Object customDeserializedValue = CustomDeserializationManager.getInstance()
                        .getDeserializer(customEncoding)
                        .deserialize(mapper.writeValueAsString(obj.get(classProperty.getName())));
                classProperty.getMutator().setValue(result, customDeserializedValue);
            } else {
                // TODO type identificatin is not safe beacuase may ne be backed by field. Rather do multiple checks
                Object value = mapper.readValue(mapper.writeValueAsString(obj.get(classProperty.getName())), classProperty.getField().getType());
                classProperty.getMutator().setValue(result, value);
            }
        }
    }
    return (T) result;
}
 
开发者ID:FraunhoferIOSB,项目名称:SensorThingsServer,代码行数:59,代码来源:CustomEntityDeserializer.java

示例7: getProperties

import com.fasterxml.jackson.databind.BeanDescription; //导入方法依赖的package包/类
private static List<BeanPropertyDefinition> getProperties(JavaType type, SerializationConfig config) {

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

		return description.findProperties();
	}
 
开发者ID:olivergierke,项目名称:jddd,代码行数:8,代码来源:SimpleValueObjectSerializerModifier.java


注:本文中的com.fasterxml.jackson.databind.BeanDescription.findProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。