Search code examples
javaapipojo

POJO for api response which has key with '-'


My api response return following response body. I have to create a POJO for this api response.

 {
            "time-since-created": 115,
            "img_url": "<Image url>",
            "heading": "Waiting for image upload",
            "name": "How are you?",
    }

Private variables for other 3 will be

private String img_url;
private String heading; 
private String img_url;

But the variable for time-since-created gives an error

Can not deserialize instance

Solution

  • Use @JsonProperty :

    @JsonProperty("time-since-created")
    private Integer timeSinceCreated;