List of usage examples for com.fasterxml.jackson.databind.jsontype NamedType getType
public Class<?> getType()
From source file:com.addthis.codec.jackson.CodecTypeIdResolver.java
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()); }//from w w w.jav a 2 s . co m } this.extraSubTypes = Maps.unmodifiableBiMap(mutableExtraSubTypes); } else { this.extraSubTypes = ImmutableBiMap.of(); } this.pluginMap = pluginMap; }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
private boolean resolveSubtypes(ModelImpl model, BeanDescription bean, ModelConverterContext context) { final List<NamedType> types = pIntr.findSubtypes(bean.getClassInfo()); if (types == null) { return false; }/* w w w . j a va 2 s.c om*/ int count = 0; final Class<?> beanClass = bean.getClassInfo().getAnnotated(); for (NamedType subtype : types) { final Class<?> subtypeType = subtype.getType(); if (!beanClass.isAssignableFrom(subtypeType)) { continue; } final Model subtypeModel = context.resolve(subtypeType); if (subtypeModel instanceof ModelImpl) { final ModelImpl impl = (ModelImpl) subtypeModel; // check if model name was inherited if (impl.getName().equals(model.getName())) { impl.setName(pTypeNameResolver.nameForType(pMapper.constructType(subtypeType), TypeNameResolver.Options.SKIP_API_MODEL)); } // remove shared properties defined in the parent final Map<String, Property> baseProps = model.getProperties(); final Map<String, Property> subtypeProps = impl.getProperties(); if (baseProps != null && subtypeProps != null) { for (Map.Entry<String, Property> entry : baseProps.entrySet()) { if (entry.getValue().equals(subtypeProps.get(entry.getKey()))) { subtypeProps.remove(entry.getKey()); } } } impl.setDiscriminator(null); ComposedModel child = new ComposedModel().parent(new RefModel(model.getName())).child(impl); context.defineModel(impl.getName(), child); ++count; } } return count != 0; }
From source file:org.deeplearning4j.nn.conf.ComputationGraphConfiguration.java
/** * Create a computation graph configuration from json * * @param json the neural net configuration from json * @return {@link org.deeplearning4j.nn.conf.ComputationGraphConfiguration} */// ww w . j a v a 2 s.c o m public static ComputationGraphConfiguration fromJson(String json) { //As per MultiLayerConfiguration.fromJson() ObjectMapper mapper = NeuralNetConfiguration.mapper(); try { return mapper.readValue(json, ComputationGraphConfiguration.class); } catch (IOException e) { //No op - try again after adding new subtypes } //Try: programmatically registering JSON subtypes for GraphVertex classes. This allows users to to add custom GraphVertex // implementations without needing to manually register subtypes //First: get all registered subtypes AnnotatedClass ac = AnnotatedClass.construct(GraphVertex.class, mapper.getSerializationConfig().getAnnotationIntrospector(), null); Collection<NamedType> types = mapper.getSubtypeResolver().collectAndResolveSubtypes(ac, mapper.getSerializationConfig(), mapper.getSerializationConfig().getAnnotationIntrospector()); Set<Class<?>> registeredSubtypes = new HashSet<>(); for (NamedType nt : types) { registeredSubtypes.add(nt.getType()); } //Second: get all subtypes of GraphVertex using reflection Reflections reflections = new Reflections(); Set<Class<? extends GraphVertex>> subTypes = reflections.getSubTypesOf(GraphVertex.class); //Third: register all subtypes that are not already registered List<NamedType> toRegister = new ArrayList<>(); for (Class<? extends GraphVertex> c : subTypes) { if (!registeredSubtypes.contains(c)) { String name; if (ClassUtils.isInnerClass(c)) { Class<?> c2 = c.getDeclaringClass(); name = c2.getSimpleName() + "$" + c.getSimpleName(); } else { name = c.getSimpleName(); } toRegister.add(new NamedType(c, name)); } } mapper = NeuralNetConfiguration.reinitMapperWithSubtypes(toRegister); try { return mapper.readValue(json, ComputationGraphConfiguration.class); } catch (IOException e) { throw new RuntimeException(e); } }