-1

I have already read many answers about the same error, but nothing helps me.

Here I try to parse Json into my data class and get an error:

ErrorResponse bodyResponse = App.getGson().fromJson(responseString, ErrorResponse.class);

The error is : BEGIN_OBJECT but was STRING

This is my response string:

'{"title":"AccessCheckException","details":{"message":"User doesn't have authorized access."}}'

And Data class:

public class ErrorResponse {
    public String title;
    public Details details;

    public ErrorResponse() {
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Details getDetails() {
        return details;
    }

    public void setDetails(Details details) {
        this.details = details;
    }}

What is wrong?

My Details class code (I reduced get/set to post it)

public class Details {
public String code;
public String msg;
public Attachment attachment;
public String message;
public String description;

public Details() {
}

}

Thanks in advance.

ManOfWar
  • 103
  • 1
  • 10

1 Answers1

0

Try this

ErrorResponse.java is mismatch with your json

    public class ErrorResponse {

    @SerializedName("title")
    @Expose
    private String title;
    @SerializedName("details")
    @Expose
    private Details details;

    public String getTitle() {
    return title;
    }

    public void setTitle(String title) {
    this.title = title;
    }

    public Details getDetails() {
    return details;
    }

    public void setDetails(Details details) {
    this.details = details;
    }

    public class Details {

    @SerializedName("message")
    @Expose
    private String message;

    public String getMessage() {
    return message;
    }

    public void setMessage(String message) {
    this.message = message;
    }

    }

    }
Ramesh sambu
  • 3,285
  • 1
  • 21
  • 37