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


Java SerializationConfig.constructType方法代码示例

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


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

示例1: getBeanSerializer

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
public static JsonSerializer<Object> getBeanSerializer(SerializerProvider sp, Class<?> cls) throws JsonMappingException {

    final SerializationConfig config = sp.getConfig();
    final JavaType type = config.constructType(cls);
    final BeanDescription beanDesc = config.introspect(type);
    return BeanSerializerFactory.instance.findBeanSerializer(sp, type, beanDesc);
  }
 
开发者ID:atgse,项目名称:sam,代码行数:8,代码来源:JsonHelper.java

示例2: buildNewAnnotatedClass

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
private static AnnotatedClass buildNewAnnotatedClass(Method method, Class<?> declaringClass,
		SerializationConfig serializationConfig)
		throws InvocationTargetException, IllegalAccessException {
	JavaType declaringType = serializationConfig.constructType(declaringClass);
	return AnnotatedClass.class.cast(method.invoke(null, declaringType, serializationConfig, serializationConfig));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:7,代码来源:AnnotatedClassBuilder.java

示例3: serialize

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的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

示例4: buildNewAnnotatedClass

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
private static AnnotatedClass buildNewAnnotatedClass(Method method, Class<?> declaringClass,
                                                     SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    JavaType declaringType = serializationConfig.constructType(declaringClass);
    return AnnotatedClass.class.cast(method.invoke(null, declaringType, serializationConfig, serializationConfig));
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:7,代码来源:AnnotatedClassBuilder.java

示例5: serialize

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
@Override
public void serialize(PagedResources pagedResources, JsonGenerator jgen, SerializerProvider serializerProvider)
        throws
        IOException {

    final SerializationConfig config = serializerProvider.getConfig();
    JavaType javaType = config.constructType(pagedResources.getClass());

    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.createSerializer(serializerProvider,
            javaType);

    // replicate pretty much everything from JacksonHydraSerializer
    // since we must reorganize the internals of pagedResources to get a hydra collection
    // with partial page view, we have to serialize pagedResources with an
    // unwrapping serializer
    Deque<LdContext> contextStack = (Deque<LdContext>) serializerProvider.getAttribute(KEY_LD_CONTEXT);
    if (contextStack == null) {
        contextStack = new ArrayDeque<LdContext>();
        serializerProvider.setAttribute(KEY_LD_CONTEXT, contextStack);
    }

    // TODO: filter next/previous/first/last from link list - maybe create new PagedResources without them?
    List<Link> links = pagedResources.getLinks();
    List<Link> filteredLinks = new ArrayList<Link>();
    for (Link link : links) {
        String rel = link.getRel();
        if (navigationRels.contains(rel)) {
            continue;
        } else {
            filteredLinks.add(link);
        }
    }

    PagedResources toRender = new PagedResources(pagedResources.getContent(), pagedResources.getMetadata(),
            filteredLinks);

    jgen.writeStartObject();

    serializeContext(toRender, jgen, serializerProvider, contextStack);

    jgen.writeStringField(JsonLdKeywords.AT_TYPE, "hydra:Collection");


    // serialize with PagedResourcesMixin
    serializer.unwrappingSerializer(NameTransformer.NOP)
            .serialize(toRender, jgen, serializerProvider);

    PagedResources.PageMetadata metadata = pagedResources.getMetadata();
    jgen.writeNumberField("hydra:totalItems", metadata.getTotalElements());

    // begin hydra:view
    jgen.writeObjectFieldStart("hydra:view");
    jgen.writeStringField(JsonLdKeywords.AT_TYPE, "hydra:PartialCollectionView");
    writeRelLink(pagedResources, jgen, Link.REL_NEXT);
    writeRelLink(pagedResources, jgen, "previous");
    // must also translate prev to its synonym previous
    writeRelLink(pagedResources, jgen, Link.REL_PREVIOUS, "previous");
    writeRelLink(pagedResources, jgen, Link.REL_FIRST);
    writeRelLink(pagedResources, jgen, Link.REL_LAST);
    jgen.writeEndObject();
    // end hydra:view


    jgen.writeEndObject();

    contextStack = (Deque<LdContext>) serializerProvider.getAttribute(KEY_LD_CONTEXT);
    if (!contextStack.isEmpty()) {
        contextStack.pop();
    }

}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:72,代码来源:PagedResourcesSerializer.java

示例6: serialize

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
@Override
public void serialize(Resource value, JsonGenerator jgen, SerializerProvider provider) throws IOException {

    final SerializationConfig config = provider.getConfig();
    JavaType javaType = config.constructType(value.getClass());

    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.createSerializer(provider, javaType);

    jgen.writeStartObject();
    serializer.unwrappingSerializer(NameTransformer.NOP)
            .serialize(value, jgen, provider);

    jgen.writeEndObject();

}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:16,代码来源:ResourceSerializer.java

示例7: serialize

import com.fasterxml.jackson.databind.SerializationConfig; //导入方法依赖的package包/类
@Override
public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException {

    final SerializationConfig config = provider.getConfig();
    JavaType javaType = config.constructType(value.getClass());

    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.createSerializer(provider, javaType);

    jgen.writeStartObject();
    serializer.serialize(value, jgen, provider);
    jgen.writeEndObject();

}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:14,代码来源:ResourcesSerializer.java


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