java 网页浏览器,http,转换器,HttpMessageConversionException:类型定义错误

olqngx59  于 2023-04-04  发布在  Java
关注(0)|答案(1)|浏览(129)

我尝试使用Resource和Simple Object返回对象,但得到错误:
网页浏览器。http。转换器。HttpMessageConversionException:类型定义错误:[simple type,class java.io.BufferedInputStream];嵌套异常为com.fasterxml.Jackson.databind.exc。无效定义异常:未找到java.io.BufferedInputStream类的序列化器,也未发现用于创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:ru.fabit.visor.ui.web.http.model.response. complex.mobilecomplex.DeviceSummaryResponse[“route”]-〉org.springframework.core.io.InputStreamResource[“inputStream”])
静置方法:

@GetMapping(DEVICE_ID_PATH)
    public ResponseEntity<DeviceSummaryResponse> getDeviceSummary(@PathVariable(name = "id") Long id) {

        log.debug("REST request to get summary for complex with id = {}", id);

        var deviceSummary = mobileComplexService.getSummary(id);

        return ResponseEntity.ok().body(deviceSummaryMapper.toResponse(deviceSummary));
    }

响应实体:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DeviceSummaryResponse {

    @ApiModelProperty(value = "Конфигурация устройства", required = true)
    private ConfigResponse config;

    @ApiModelProperty(value = "GPX файл с маршрутом устройства", required = true)
    private Resource route;
}

如何返回此对象?

gr8qqesn

gr8qqesn1#

您的Resource路由包含不可序列化的内容,即java.io.BufferedInputStream。
尝试禁用SerializationFeature.FAIL_ON_EMPTY_BEANS。如果不起作用,则需要重新构造,以便不引用BufferedInputStream或任何其他不可Serializable的类。

相关问题