本文整理汇总了Java中com.fasterxml.jackson.databind.jsontype.NamedType类的典型用法代码示例。如果您正苦于以下问题:Java NamedType类的具体用法?Java NamedType怎么用?Java NamedType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NamedType类属于com.fasterxml.jackson.databind.jsontype包,在下文中一共展示了NamedType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectMapper
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
final YAMLFactory yamlFactory = new YAMLFactory()
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);
ObjectMapper mapper = new ObjectMapper(yamlFactory)
.registerModule(new Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.enable(SerializationFeature.INDENT_OUTPUT)
.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
}
return mapper;
}
示例2: createObjectMapper
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
final YAMLFactory yamlFactory = new YAMLFactory()
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
.configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);
ObjectMapper mapper = new ObjectMapper(yamlFactory)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.enable(SerializationFeature.INDENT_OUTPUT)
.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
}
return mapper;
}
示例3: extendMapper
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
@Override
public void extendMapper(ObjectMapper mapper)
{
List<AttachmentSerializer> serializers = tracker.getBeanList();
for( AttachmentSerializer attachmentSerializer : serializers )
{
Map<String, Class<? extends EquellaAttachmentBean>> types = attachmentSerializer.getAttachmentBeanTypes();
if( types != null )
{
for( Entry<String, Class<? extends EquellaAttachmentBean>> entry : types.entrySet() )
{
mapper.registerSubtypes(new NamedType(entry.getValue(), entry.getKey()));
}
}
}
}
示例4: findSubtypes
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
@Override
public List<NamedType> findSubtypes(Annotated a)
{
final ApiModel api = a.getAnnotation(ApiModel.class);
if (api != null) {
final Class<?>[] classes = api.subTypes();
final List<NamedType> names = new ArrayList<>(classes.length);
for (Class<?> subType : classes) {
names.add(new NamedType(subType));
}
if (!names.isEmpty()) {
return names;
}
}
return Collections.emptyList();
}
示例5: assertConverterBeanAfterPropertiesSet
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
private void assertConverterBeanAfterPropertiesSet(
final String[] expectedPackageToScan,
final Class<?>... expectedRegisterdClasses) {
final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(converter,
"mapper");
@SuppressWarnings("unchecked")
final LinkedHashSet<NamedType> registeredSubtypes = (LinkedHashSet<NamedType>) ReflectionTestUtils
.getField(mapper.getSubtypeResolver(), "_registeredSubtypes");
final List<Class<?>> expectedRegisterdClassesAsList = new ArrayList<>(
Arrays.asList(expectedRegisterdClasses));
addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList);
assertTrue("Wrong RemoteApplicationEvent classes are registerd in object mapper",
expectedRegisterdClassesAsList.size() == registeredSubtypes.size());
for (final NamedType namedType : registeredSubtypes) {
assertTrue(expectedRegisterdClassesAsList.contains(namedType.getType()));
}
assertThat("RemoteApplicationEvent packages not registered",
Arrays.asList((String[]) ReflectionTestUtils.getField(converter, "packagesToScan")),
containsInAnyOrder(expectedPackageToScan));
}
示例6: collectAndResolveSubtypes
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass paramAnnotatedClass, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector)
{
HashMap localHashMap = new HashMap();
if (this._registeredSubtypes != null)
{
Class localClass = paramAnnotatedClass.getRawType();
Iterator localIterator = this._registeredSubtypes.iterator();
while (localIterator.hasNext())
{
NamedType localNamedType = (NamedType)localIterator.next();
if (localClass.isAssignableFrom(localNamedType.getType()))
_collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
}
}
_collectAndResolve(paramAnnotatedClass, new NamedType(paramAnnotatedClass.getRawType(), null), paramMapperConfig, paramAnnotationIntrospector, localHashMap);
return new ArrayList(localHashMap.values());
}
示例7: buildTypeDeserializer
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public TypeDeserializer buildTypeDeserializer(DeserializationConfig paramDeserializationConfig, JavaType paramJavaType, Collection<NamedType> paramCollection)
{
if (this._idType == JsonTypeInfo.Id.NONE)
return null;
TypeIdResolver localTypeIdResolver = idResolver(paramDeserializationConfig, paramJavaType, paramCollection, false, true);
switch (1.$SwitchMap$com$fasterxml$jackson$annotation$JsonTypeInfo$As[this._includeAs.ordinal()])
{
default:
break;
case 1:
return new AsArrayTypeDeserializer(paramJavaType, localTypeIdResolver, this._typeProperty, this._typeIdVisible, this._defaultImpl);
case 2:
return new AsPropertyTypeDeserializer(paramJavaType, localTypeIdResolver, this._typeProperty, this._typeIdVisible, this._defaultImpl);
case 3:
return new AsWrapperTypeDeserializer(paramJavaType, localTypeIdResolver, this._typeProperty, this._typeIdVisible, this._defaultImpl);
case 4:
return new AsExternalTypeDeserializer(paramJavaType, localTypeIdResolver, this._typeProperty, this._typeIdVisible, this._defaultImpl);
}
throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: " + this._includeAs);
}
示例8: buildTypeSerializer
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public TypeSerializer buildTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, Collection<NamedType> paramCollection)
{
if (this._idType == JsonTypeInfo.Id.NONE)
return null;
TypeIdResolver localTypeIdResolver = idResolver(paramSerializationConfig, paramJavaType, paramCollection, true, false);
switch (1.$SwitchMap$com$fasterxml$jackson$annotation$JsonTypeInfo$As[this._includeAs.ordinal()])
{
default:
break;
case 1:
return new AsArrayTypeSerializer(localTypeIdResolver, null);
case 2:
return new AsPropertyTypeSerializer(localTypeIdResolver, null, this._typeProperty);
case 3:
return new AsWrapperTypeSerializer(localTypeIdResolver, null);
case 4:
return new AsExternalTypeSerializer(localTypeIdResolver, null, this._typeProperty);
}
throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: " + this._includeAs);
}
示例9: idResolver
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
protected TypeIdResolver idResolver(MapperConfig<?> paramMapperConfig, JavaType paramJavaType, Collection<NamedType> paramCollection, boolean paramBoolean1, boolean paramBoolean2)
{
if (this._customIdResolver != null)
return this._customIdResolver;
if (this._idType == null)
throw new IllegalStateException("Can not build, 'init()' not yet called");
switch (1.$SwitchMap$com$fasterxml$jackson$annotation$JsonTypeInfo$Id[this._idType.ordinal()])
{
default:
break;
case 1:
return new ClassNameIdResolver(paramJavaType, paramMapperConfig.getTypeFactory());
case 2:
return new MinimalClassNameIdResolver(paramJavaType, paramMapperConfig.getTypeFactory());
case 3:
return TypeNameIdResolver.construct(paramMapperConfig, paramJavaType, paramCollection, paramBoolean1, paramBoolean2);
case 4:
return null;
}
throw new IllegalStateException("Do not know how to construct standard type id resolver for idType: " + this._idType);
}
示例10: startRealtime
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
private static synchronized void startRealtime() {
if (rn == null) {
final Lifecycle lifecycle = new Lifecycle();
rn = RealtimeNode.builder().build();
lifecycle.addManagedInstance(rn);
rn.registerJacksonSubtype(new NamedType(StormFirehoseFactory.class, "storm"));
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
LOG.info("Running shutdown hook");
lifecycle.stop();
}
}));
try {
lifecycle.start();
} catch (Throwable t) {
LOG.info("Throwable caught at startup, committing seppuku", t);
t.printStackTrace();
System.exit(2);
}
}
}
示例11: CodecTypeIdResolver
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public CodecTypeIdResolver(PluginMap pluginMap, JavaType baseType,
TypeFactory typeFactory, Collection<NamedType> subtypes,
PluginRegistry pluginRegistry) {
super(baseType, typeFactory);
this.pluginRegistry = pluginRegistry;
if (!subtypes.isEmpty()) {
BiMap<String, Class<?>> mutableExtraSubTypes = HashBiMap.create(subtypes.size());
for (NamedType namedType : subtypes) {
if (namedType.hasName()) {
mutableExtraSubTypes.put(namedType.getName(), namedType.getType());
}
}
this.extraSubTypes = Maps.unmodifiableBiMap(mutableExtraSubTypes);
} else {
this.extraSubTypes = ImmutableBiMap.of();
}
this.pluginMap = pluginMap;
}
示例12: findSubtypes
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
/** report all non-alias plugin types */
@Override
public List<NamedType> findSubtypes(Annotated a) {
Pluggable pluggable = a.getAnnotation(Pluggable.class);
PluginMap pluginMap;
if (pluggable != null) {
pluginMap = pluginRegistry.byCategory().get(pluggable.value());
} else if (pluginRegistry.byClass().containsKey(a.getRawType())) {
pluginMap = pluginRegistry.byClass().get(a.getRawType());
} else {
return null;
}
List<NamedType> result = new ArrayList<>(pluginMap.asBiMap().size());
for (Map.Entry<String, Class<?>> type : pluginMap.asBiMap().entrySet()) {
result.add(new NamedType(type.getValue(), type.getKey()));
}
return result;
}
示例13: jacksonObjectMapper
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
@Bean
public ObjectMapper jacksonObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(
mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(Visibility.ANY)
.withGetterVisibility(Visibility.NONE)
.withSetterVisibility(Visibility.NONE)
.withCreatorVisibility(Visibility.NONE)
.withIsGetterVisibility(Visibility.NONE));
SimpleModule module = new SimpleModule("bandwidth-on-demand", Version.unknownVersion());
module.addSerializer(new VlanJsonSerializer());
module.addDeserializer(Vlan.class, new VlanJsonDeserializer());
module.addSerializer(new ScheduleTypeJsonSerializer());
module.addDeserializer(ScheduleType.class, new ScheduleTypeJsonDeserializer());
mapper.registerModule(module);
mapper.registerModule(new Hibernate4Module());
mapper.registerModule(new JodaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.registerSubtypes(new NamedType(LocalVirtualPort.class, "LOCAL"));
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}
示例14: collectAndResolveSubtypes
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
@Override
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass type,
MapperConfig<?> config, AnnotationIntrospector ai)
{
HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>();
// [JACKSON-257] then consider registered subtypes (which have precedence over annotations)
if (_registeredSubtypes != null) {
Class<?> rawBase = type.getRawType();
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type?
if (rawBase.isAssignableFrom(subtype.getType())) { // yes
AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
_collectAndResolve(curr, subtype, config, ai, subtypes);
}
}
}
// and then check subtypes via annotations from base type (recursively)
NamedType rootType = new NamedType(type.getRawType(), null);
_collectAndResolve(type, rootType, config, ai, subtypes);
return new ArrayList<NamedType>(subtypes.values());
}
示例15: buildTypeSerializer
import com.fasterxml.jackson.databind.jsontype.NamedType; //导入依赖的package包/类
public TypeSerializer buildTypeSerializer(SerializationConfig config,
JavaType baseType, Collection<NamedType> subtypes)
{
if (_idType == JsonTypeInfo.Id.NONE) {
return null;
}
TypeIdResolver idRes = idResolver(config, baseType, subtypes, true, false);
switch (_includeAs) {
case WRAPPER_ARRAY:
return new AsArrayTypeSerializer(idRes, null);
case PROPERTY:
return new AsPropertyTypeSerializer(idRes, null,
_typeProperty);
case WRAPPER_OBJECT:
return new AsWrapperTypeSerializer(idRes, null);
case EXTERNAL_PROPERTY:
return new AsExternalTypeSerializer(idRes, null,
_typeProperty);
}
throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: "+_includeAs);
}