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