當前位置: 首頁>>代碼示例>>Java>>正文


Java SerializerProvider.getConfig方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.SerializerProvider.getConfig方法的典型用法代碼示例。如果您正苦於以下問題:Java SerializerProvider.getConfig方法的具體用法?Java SerializerProvider.getConfig怎麽用?Java SerializerProvider.getConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.SerializerProvider的用法示例。


在下文中一共展示了SerializerProvider.getConfig方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import com.fasterxml.jackson.databind.SerializerProvider; //導入方法依賴的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


注:本文中的com.fasterxml.jackson.databind.SerializerProvider.getConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。