JSON 不返回 Spring Data REST 中的列

标签 json spring rest spring-data-jpa spring-data-rest

我正在尝试 Spring Data REST 的示例,但是在我的测试中返回的 JSON 对象不返回列名(之前是“PUT”),只是返回对象的链接。有什么问题吗?

Scenario:

实体:“用户”

@Entity
@Data
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String guid;
    private String fullName;
    private String email;
}

存储库:UserRepository(公开为 REST 服务)

@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {
}

创建 USER 对象的 REST“PUT”请求:

enter image description here

REST GET 调用以获取用户对象的 JSON 响应(问题) enter image description here

No id, Guid or email is returned in the JSON response.

最佳答案

删除 lombok 的 @Data 注释使所有基本属性都出现在 JSON 响应中。看起来像是 lombok 的副作用。

关于JSON 不返回 Spring Data REST 中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149426/

相关文章:

android - 如何在 API 调用中转义特殊字符?

json - 将任何 JSON 解析为 JValue 而不指定案例类

java - Spring Boot/JUnit,为多个配置文件运行所有单元测试

javascript - 查询大型 JSON 对象的条件

java - Spring MVC - 如果未登录,如何重定向到登录

java - 来自 DB 的图像不会在 JSP 中显示 : No mapping found for HTTP request

rest - 为什么 JerseyTest 抛出 ConstraintViolationException 而不是返回 400 Bad Request?

json - future 证明 : Is removing a JSON envelope the current best practice?

javascript - 如何将 'map' 与数组中的数组一起使用 (Json)

javascript - 在 Nodejs 中解析大型 JSON 文件并独立处理每个对象