本文整理汇总了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();
}
}
}