spring-bootcouchdbcloudant

How to map properties on the CouchDB document to java model object?


I have within a database a set of documents in CouchDB where their structure is as follow :

    {
      "_id": "adebafb022857385a4c970b0f0000349",
      "_rev": "2-19d78f4d8d6386bfbe7b2c03b5213830",
      "street_number": "20",
      "street_name": "B.Baker St",
      "city_name": "Marylebone",
      "zip_code": "2550",
      "status": "active"
    }

as you can see the properties are not camel-cased, I have tried to make the mapping using JsonProperty, however, I get null value in all properties except for status property.

enter image description here

I have pushed the code in this repo link

Any help is much appreciated

Regarding the CouchDB, I using a docker container with CouchDB image.


Solution

  • I have used com.google.code.gson dependency with @SerializedName as follows:

    package com.example.couch_mapping.model;
    
    import com.google.gson.annotations.*;
    import lombok.Data;
    
    @Data
    public class AddressDto {
        @SerializedName("_id")
        String id;
    
        @SerializedName("_rev")
        String revision;
    
        @SerializedName("street_number")
        String streetNumber;
    
        @SerializedName("street_name")
        String streetName;
    
        @SerializedName("city_name")
        String cityName;
    
        @SerializedName("zip_code")
        String zipCode;
    
        String status;
    }