java - 为了避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)

标签 java spring spring-boot resttemplate

我正在尝试将 HttpServletRequest 路由到另一个微服务,其中请求可能包含多部分请求或任何正常请求。但在发送时我收到以下错误。

注意:我不想修改请求,因为我正在尝试编写一些通用方法。

public Object doPostCall(HttpServletRequest request, String requestURL, String rootURL)
            throws URISyntaxException, IOException, ServletException {

        RestTemplate restTemplate = new RestTemplate();
        final String url = rootURL + requestURL;
        uri = new URI(url);

        try {
            result2 = restTemplate.postForEntity(uri, request, Object.class);
            System.out.println("after service call" + result2);
        } catch (RestClientException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result2;
    }

com.fasterxml.jackson.databind.exc.InvalidDefinitionException:

No serializer found for class java.util.Collections$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest["request"]->org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper["request"]->org.apache.catalina.connector.RequestFacade["attributeNames"])

即使我尝试在属性文件中设置它。 spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false,但它不起作用

我的消费 Controller 如下所示:

@PostMapping(value = "/v1/upload/{moduleName}/{fileType}", produces = "application/json")
    public ResponseEntity<Object> uploadFiles(@RequestPart("file") List<MultipartFile> inputFileList,
            @RequestParam(value = "createdBy", required = false) String createdBy, @PathVariable String moduleName,
            @RequestParam(value = "catalogId", required = false) String catalogId,
            @RequestParam(value = "catalogName", required = false) String catalogName, @PathVariable String fileType) {

最佳答案

尝试使用 @JsonIgnoreProperties("hibernateLazyInitializer") 注释您的实体类

关于java - 为了避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57218236/

相关文章:

java - Log4j 不打印第 3 方日志(Spring.Hibernate 等)到 RollingFileAppender

java - 使用 SFTP 入站重新下载本地删除的文件的过程是什么

java - Spring - 无法读取 HTTP 消息。缺少必需的请求正文

spring - 在 Spring Boot 应用程序中添加 Servlet 过滤器

java - 如何将进入/退出 Java 操作添加到自定义流程图 block

java - 从自定义适配器重写 getContextMenuInfo()

java - Jax-ws : Java SOAP exception :MustUnderstand headers:[{http://www. w3.org/2005/08/addressing} Action

java - 如何使用 procrun windows 服务执行器从 spring-boot 启动可执行 jar?

mysql - 用户 '' @'localhost' 的访问被拒绝(使用密码 : NO) spring-boot

java - 如何将 Kafka Producer 的指标报告给 prometheus(使用 spring boot)