當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。