java.io.EOFException : No content to map to Object due to end of input while retrieving data

标签 java spring-boot jpa

尝试从表中获取数据时出现以下错误。

java.io.EOFException: No content to map to Object due to end of input

错误发生在下面一行:

try {
			if (pgObject == null) {
			return new ObjectMapper().readValue("", Map.class); // error here
			}else {
				return new ObjectMapper().readValue(pgObject.getValue(), Map.class);
			}
		} catch (IOException e) {
		//	System.out.println("Exception Occured in json converter 1");
			e.printStackTrace();
			return null;
		}

enter image description here

最佳答案

要返回空 map ,您必须使用以下内容:

mapper.readValue("{}", Map.class);

因为空字符串 "" 并不意味着空 JSON。空 JSON 由 {} 指示。在类似的行上,JSON 中的空数组由 []

指示

关于java.io.EOFException : No content to map to Object due to end of input while retrieving data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59043316/

相关文章:

java - 在现有应用程序中实现缓存

java - 尝试使用 Spring 验证请求正文时,出现 "Invalid property ' ssn ' of bean class [java.lang.String]"

带有更改 where 子句的 JPA 查询

java - 通过方法处理数组

java - 使用 Java 绘制基于输入实时更新的图形?

java - 如何删除 java keystore 个人/私有(private)密码

java - 如何在@Query注释中使用方法参数作为纯文本

java - 从 application.properties Spring Boot 中读取值

spring-boot - Spring Boot +休眠搜索:必需的索引状态被忽略?

java - JPA:查询以根据实体类中定义的外键值获取结果?