How to hande error null body in retrofit?

Im trying to post data with retrofit with jwt bearer authentication, but when i debug response code, its error 400, and the message is body = null

This is my Intefrace class

@Headers({"accept: text/plain","Content-Type: application/json-patch+json"    })
    Call<ProjectRequest> postProject(@Header("Authorization") String token,
                                     @Body ProjectRequest projectRequest

This is my model class

public class ProjectRequest {
    private String name;

    private String description;

    private int ownerId;

    private String startPeriod;

    private String endPeriod;

    private boolean isDraft;

    private String ownerName;

    private int pitId;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public String getDescription() {
        return description;

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

    public int getOwnerId() {
        return ownerId;

    public void setOwnerId(int ownerId) {
        this.ownerId = ownerId;

    public String getStartPeriod() {
        return startPeriod;

    public void setStartPeriod(String startPeriod) {
        this.startPeriod = startPeriod;

    public String getEndPeriod() {
        return endPeriod;

    public void setEndPeriod(String endPeriod) {
        this.endPeriod = endPeriod;

    public boolean isDraft() {
        return isDraft;

    public void setDraft(boolean draft) {
        isDraft = draft;

    public String getOwnerName() {
        return ownerName;

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;

    public int getPitId() {
        return pitId;

    public void setPitId(int pitId) {
        this.pitId = pitId;

And the main class is

    private void initApi() {
        projectApi = ApiClient.getClient().create(ProjectApi.class);

    private void postProject(final boolean isOnline) {
        if (isOnline) {
            final ProjectRequest projectRequest = new ProjectRequest();
            projectRequest.setOwnerName("yogi kun");

            Call<ProjectRequest> callProject = projectApi.postProject(" Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6Il and so . . . ",
            callProject.enqueue(new Callback<ProjectRequest>() {
                public void onResponse(@NotNull Call<ProjectRequest> call, @NotNull Response<ProjectRequest> response) {
                    if (response.isSuccessful()) {
                        try {
                            Toast.makeText(getContext(), "Success", Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            String message = "";
                            if (e.getMessage() != null) {
                                message = e.getMessage();
                            Toast.makeText(getContext(), "Failed " + message, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getContext(), "Failed " + response, Toast.LENGTH_SHORT).show();

                public void onFailure(@NotNull Call<ProjectRequest> call, @NotNull Throwable t) {
                    Toast.makeText(getContext(), "Failure" + t, Toast.LENGTH_SHORT).show();

And the error is

enter image description here


enter image description here


Might be an issue with how the JSON is formatted, compared to what you’re expecting. Are you able to use something like Postman and try this API call to see the format it comes back? Can’t tell that much but the error message shown is finding some array somewhere in the JSON

Source: stackoverflow