Michael dela Cruz
Michael dela Cruz

Reputation: 3

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

I am new to couchbase and I am encountering an issue on fetching document from couchbase. The nested list of object (List of Devices) is always null. I used Spring Boot and Spring Data Couchbase.

Model (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 **/
}

Model (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

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

   User findOneByUsername(String username);

   User findOneByDeviceId(String deviceId);
}

Document

{
   "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"
    }
  ]
}

Result

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

I hope you could help me regarding this matter. Thank you in advance

Upvotes: 0

Views: 586

Answers (1)

talhaocakci
talhaocakci

Reputation: 141

In your class, attribute name is deviceList but in json it is devicesList. The persisted json can not be converted to POJO since the attribute names are different.

Upvotes: 1

Related Questions