public static JavaType type(Type type) { return OBJECT_MAPPER.constructType(type); }
@Override protected boolean canConvertFrom(Message<?> message, @Nullable Class<?> targetClass) { if (targetClass == null || !supportsMimeType(message.getHeaders())) { return false; } JavaType javaType = this.objectMapper.constructType(targetClass); AtomicReference<Throwable> causeRef = new AtomicReference<>(); if (this.objectMapper.canDeserialize(javaType, causeRef)) { return true; } logWarningIfNecessary(javaType, causeRef.get()); return false; }
private JavaType getJavaType(Class<?> targetClass, @Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter param = (MethodParameter) conversionHint; param = param.nestedIfOptional(); if (Message.class.isAssignableFrom(param.getParameterType())) { param = param.nested(); } Type genericParameterType = param.getNestedGenericParameterType(); Class<?> contextClass = param.getContainingClass(); Type type = GenericTypeResolver.resolveType(genericParameterType, contextClass); return this.objectMapper.getTypeFactory().constructType(type); } return this.objectMapper.constructType(targetClass); }
@Autowired public JacksonRequestStreamHandler(ObjectMapper mapper, RequestHandler<IN, OUT> innerHandler) { this.innerHandler = innerHandler; Map<TypeVariable<?>, Type> arguments = TypeUtils.getTypeArguments(innerHandler.getClass(), RequestHandler.class); Type inputType = arguments.get(PARAMETERS[0]); Type outputType = arguments.get(PARAMETERS[1]); this.reader = mapper.readerFor(mapper.constructType(inputType)); this.writer = mapper.writerFor(mapper.constructType(outputType)); }
@Override public void validate(Object var,List<ActivitiException> errors) { //we can consider var json so long as it can be stored as json //this doesn't guarantee a string body to be valid json as jackson will wrap a string to make it valid //also doesn't guarantee it will be persisted as json //could be a pojo and then could be persisted as serializable if user sets serializePOJOsInVariablesToJson to false - see JsonType.java if (!objectMapper.canSerialize(var.getClass())){ String message = var.getClass()+" is not serializable as json"; errors.add(new ActivitiException(message)); logger.error(message); } if (!objectMapper.canDeserialize(objectMapper.constructType(var.getClass()))){ String message = var.getClass()+" is not deserializable as json"; errors.add(new ActivitiException(message)); logger.error(message); } } }
private void removeSuperSubTypes(List<NamedType> resultTypes, Class<?> superClass) { JavaType superType = _mapper.constructType(superClass); BeanDescription superBean = _mapper.getSerializationConfig().introspect(superType); final List<NamedType> superTypes = _intr.findSubtypes(superBean.getClassInfo()); if (superTypes != null) { resultTypes.removeAll(superTypes); } }
public static String name(Type type) { return name(Json.mapper().constructType(type)); }
@GET @Path("{configClass}") @Produces(MoreMediaTypes.APPLICATION_SCHEMA_JSON) @ApiOperation(value = "Get JSON schema of configuration class") @Timed @RequiresPermissions(RestPermissions.CLUSTER_CONFIG_ENTRY_READ) public JsonSchema schema(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass) { final Class<?> cls = classFromName(configClass); if (cls == null) { throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\""); } final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(cls), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for configuration class " + configClass, e); } return visitor.finalSchema(); }
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) { final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName); if (provider == null) { throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName); } final RetentionStrategy retentionStrategy = provider.get(); final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e); } return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema()); } }
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) { final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName); if (provider == null) { throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName); } final RotationStrategy rotationStrategy = provider.get(); final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e); } return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema()); } }
.introspect(mapper.constructType(clazz)) .findProperties(); for (BeanPropertyDefinition beanDef : beanDefs) {
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { final JavaType jType = Json.mapper().constructType(type.getType()); if (jType != null) { final Class<?> cls = jType.getRawClass(); if (cls.equals(Bar.class)) { return null; } else { return chain.next().resolve(type, context, chain); } } else { return null; } } }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } JavaType javaType = mapper.constructType(type.getType()); if (matcher.matches(ctype) && mapper.canDeserialize(javaType)) { return ctx .ifparam(values -> mapper.readValue(values.iterator().next(), javaType)) .ifbody(body -> mapper.readValue(body.bytes(), javaType)); } return ctx.next(); }
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (type.isSchemaProperty()) { JavaType _type = Json.mapper().constructType(type.getType()); if (_type != null) { Class<?> cls = _type.getRawClass(); if (MyCustomClass.class.isAssignableFrom(cls)) { return new DateTimeSchema(); } } } if (chain.hasNext()) { return chain.next().resolve(type, context, chain); } else { return null; } } }
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (type.isSchemaProperty()) { JavaType _type = Json.mapper().constructType(type.getType()); if (_type != null) { Class<?> cls = _type.getRawClass(); if (MyCustomClass.class.isAssignableFrom(cls)) { Schema schema = new DateTimeSchema(); super.resolveSchemaMembers(schema, type); return schema; } } } if (chain.hasNext()) { return chain.next().resolve(type, context, chain); } else { return null; } } }
/** * Mostly for kotlin null safe operator and immutable properties. * * @param type Target type. * @param model Model. * @return Input model. */ private Model doModel(Type type, Model model) { Map<String, Property> properties = model.getProperties(); if (properties != null) { BeanDescription desc = Json.mapper().getSerializationConfig() .introspect(Json.mapper().constructType(type)); for (BeanPropertyDefinition beanProperty : desc.findProperties()) { Property property = properties.get(beanProperty.getName()); if (property != null) { property.setRequired(beanProperty.isRequired()); } } } return model; }
javaType = (JavaType)type.getType(); } else { javaType = mapper.constructType(type.getType());
protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType) { final JavaType type; if (annotatedType.getType() instanceof JavaType) { type = (JavaType) annotatedType.getType(); } else { type = _mapper.constructType(annotatedType.getType()); } final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type); final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation = resolvedSchemaOrArrayAnnotation == null ? null : resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ? ((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() : (io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation; final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type); Annotated a = beanDesc.getClassInfo(); Annotation[] annotations = annotatedType.getCtxAnnotations(); resolveSchemaMembers(schema, a, annotations, schemaAnnotation); }
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { final JavaType javaType = _mapper.constructType(type.getType()); if (Pair.class.isAssignableFrom(javaType.getRawClass())) { final JavaType left = javaType.containedType(0); final String name = "MapOf" + WordUtils.capitalize(_typeName(left)); return new MapSchema() .name(name) .additionalProperties(context.resolve(new AnnotatedType(left))); } return super.resolve(type, context, chain); } }
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { final JavaType javaType = _mapper.constructType(type.getType()); if (Pair.class.isAssignableFrom(javaType.getRawClass())) { if (!type.isSchemaProperty()) {