Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parse snake case fields in a FeignClient response json?

I have configured a FeignClient in my spring boot webapp where I'm calling an external api that returns the following object.

public class Issue {

    private Assignee assignee;
    private Date createdAt;
    private Date updatedAt;
    private Date closedAt;
    private String description;
    private Date dueDate;

    public Assignee getAssignee() {
        return assignee;
    }

    public void setAssignee(Assignee assignee) {
        this.assignee = assignee;
    }


    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
    this.dueDate = dueDate;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Date getClosedAt() {
        return closedAt;
    }

    public void setClosedAt(Date closedAt) {
        this.closedAt = closedAt;
    }


    @Override
    public String toString() {
        return (JacksonJson.toJsonString(this));
    }
}

The fields updatedAt, createdAt and closedAt are all in snake case. All multi-word fields show up as null. Is there any way of configuring the FeignClient's Jackson parser so that it can process snake case characters? Note, that I cannot change the default Jackson Parser for my spring boot webapp because I myself render json in camel case. I just need to configure this parser on the FeignClient that I'm using to connect to an external REST api.

I have verified that the json response returned from the api call contains valid values in each of these json fields.

like image 749
horatius Avatar asked Jan 29 '26 11:01

horatius


1 Answers

To solve this issue I have used @JsonNaming annotation, which is available in jackson-databind:2.11.4 library. In annotation parameter you need to define property naming strategy for json parsing. In our case PropertyNamingStrategy.SnakeCaseStrategy.class does the trick. Naming strategy is changed only for the entity under annotation, other places of application are not affected.

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Issue {...}
like image 197
Markas Sislo Avatar answered Jan 31 '26 00:01

Markas Sislo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!