Spring Data Couchbase / Spring Boot:无法获取对象的嵌套列表

Spring Data Couchbase / Spring Boot: could not get nested list of an object

我是 couchbase 的新手,我在从 couchbase 获取文档时遇到了问题。对象的嵌套列表(设备列表)始终为空。我使用了 Spring Boot 和 Spring Data Couchbase。

型号(User.java)

@Document
public class User implements Serializable {
   @Id
   private String id;

   @Field
   @NotNull
   private String username;

   @Field
   @NotNull
   private String password;

   @Field
   private List<Devices> deviceList;

   /** getter and setter here **/
}

型号(Devices.java)

@Document
public class Devices implements Serializable {
   @Field
   @NotNull
   private String deviceId;

   @Field
   @NotNull
   private String status;

   @Field
   @NotNull
   private String createdDate;

   @Reference
   private User user;

   /** getter and setter here **/
}

存储库

@Repository
@Transactional
@N1qlPrimaryIndexed
public interface UserRepository extends CouchbaseRepository<User, String>{

   User findOneByUsername(String username);

   User findOneByDeviceId(String deviceId);
}

文档

{
   "username": "username",
   "password": "password",
   "devicesList": [
    {
      "deviceId": "abc123",
      "status": "deactived",
      "createdDate": "2017-07-28 15:59:13"
    },
    {
      "deviceId": "abc456",
      "status": "actived",
      "createdDate": "2017-07-28 15:59:13"
    },
    {
      "deviceId": "abc789",
      "status": "deactived",
      "createdDate": "2017-07-28 15:59:13"
    }
  ]
}

结果

{
   "responseCode": 200,
   "data": {
      "id": "user-login-03",
      "username": "username",
      "password": "password",
      "deviceList": null
   }
}

我希望你能帮助我解决这个问题。提前谢谢你

在您的 class 中,属性名称是 deviceList,但在 json 中是 devicesList。 由于属性名称不同,持久化的 json 无法转换为 POJO。