我尝试返回对象与资源和简单的对象,但得到错误:
org.springframework.http.converter.HttpMessageConversionException:类型定义错误:[简单类型,类。java.io.BufferedInputStream];嵌套异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:不为java.io.BufferedInputStream类找到序列化器属性发现创建BeanSerializer(以避免异常,禁用SerializationFeature.FAIL_ON_EMPTY_BEANS(通过引用)链:ru.fabit.visor.ui.web.http.model.response.complexes.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;
}
我如何返回这个对象?
您的资源路由包含不可序列化的内容,例如java.io.BufferedInputStream.
尝试禁用SerializationFeature.FAIL_ON_EMPTY_BEANS。如果这不起作用,您将需要重新构建,以便不引用BufferedInputStream或任何其他不可序列化的类。