i am calling a api in android using retrofit and trying to get json object as a response and map that json object onto my model object but i am getting this error
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 12 column 22 path $.data[0].salary
i cant change anything in the server response because i am dealing with only front end, so if there is anything wrong even with the server response please let me know how can i handle that thing on my end
Server Response
{
"header": "200",
"status": "success",
"data": [
{
"id": 1,
"job_title": "Software Engineer",
"city": "Yogyakarta",
"country": "Indonesia",
"logo": "https://s3-ap-southeast-1.amazonaws.com/ricebowl/employers/4913.png",
"company_name": "A Job Thing",
"salary": {
"currency": "IDR",
"minimum": "5000000",
"maximum": "10000000"
},
"created_at": "2018-10-01T00:30:00+0000",
"job_type": "Full Time",
"share_url":"https://ajobthing.com/",
"description": "A Job Thing is a recruitment platform tools for hiring better staff. AJobThing helping facilitate the recruitment process of talented candidates for the organization. We attract the best candidates allowing us the opportunity to source and select the best talents to match company requirements.\n\nIn March 2018, A Job Thing became the best Job Portal and Win Asia Recruitment Awards 2018 held by HR Asia Recruitment. We are committed to continuously improving the value we provide as best HR tools to help hiring talented candidates. To deliver on this, we continue to evolve our platform and service offerings to be the best recruiting tools.",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
},
{
"id": 2,
"job_title": "Software Engineer",
"city": "Istanbul",
"country": "Turkey",
"logo": "https://zeplin.io/img/favicon/256x256.png",
"company_name": "Zeplin",
"salary": {
"currency": "USD",
"minimum": "5000",
"maximum": "10000"
},
"created_at": "2018-10-02T23:18:00+0000",
"job_type": "Internship",
"share_url":"https://ajobthing.com/",
"description": "Zeplin is a connected space for product teams where they can share designs, generate specs, assets and code snippets. In just 2 years, we’ve reached over 1,500,000 users from the best product teams like Airbnb, Dropbox, Pinterest, Microsoft and many many more. We’re a Y Combinator startup, also backed by amazing investors like Elad Gil, Mike Maples, Kevin Hale. We’re a small, distributed crew with offices in San Francisco and Istanbul.",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
},
{
"id": 3,
"job_title": "Software Engineer",
"city": "Singapore",
"country": "Singapore",
"logo": "https://grab.careers/wp-content/themes/grabcareer/images/Grab_logo.png",
"company_name": "Grab",
"salary": {
"currency": "SGD",
"minimum": "5000",
"maximum": "10000"
},
"created_at": "2018-10-10T00:30:00+0000",
"job_type": "Full Time",
"share_url":"https://ajobthing.com/",
"description": "Grab is more than just the leading ride-hailing app in Southeast Asia. We use data and technology to improve everything from transportation to payments and logistics across Southeast Asia.\n\nWorking with governments, drivers, passengers and charities, we aim to unlock the true potential of the region by solving the problems that hinder progress. If you share our vision of Driving Southeast Asia Forward, apply to join our team today.",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
},
{
"id": 4,
"job_title": "Software Engineer",
"city": "Jakarta",
"country": "Indonesia",
"logo": "https://teatoxnco.com/store/wp-content/uploads/2017/08/logo-tokopedia.png",
"company_name": "Tokopedia",
"salary": {
"currency": "IDR",
"minimum": "5000000",
"maximum": "10000000"
},
"created_at": "2018-10-11T23:18:00+0000",
"job_type": "Internship",
"share_url":"https://ajobthing.com/",
"description": "Tokopedia is an Indonesian technology company with a mission to democratize commerce through technology. We are the leading marketplace in Indonesia; we encourage millions of merchants and consumers to participate in the future of commerce. Our vision is to build an ecosystem where everyone can start and discover anything with ease",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
},
{
"id": 5,
"job_title": "Software Engineer",
"city": "Remote",
"logo": "https://images-na.ssl-images-amazon.com/images/I/51rttY7a%2B9L._SY355_.png",
"company_name": "Spotify",
"salary": {
"currency": "EUR",
"minimum": "5000",
"maximum": "10000"
},
"created_at": "2018-10-12T00:30:00+0000",
"job_type": "Full Time",
"share_url":"https://ajobthing.com/",
"description": "With Spotify, it’s easy to find the right music for every moment – on your phone, your computer, your tablet and more.\n\nThere are millions of tracks on Spotify. So whether you’re working out, partying or relaxing, the right music is always at your fingertips. Choose what you want to listen to, or let Spotify surprise you.\n\nYou can also browse through the music collections of friends, artists and celebrities, or create a radio station and just sit back.",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
},
{
"id": 6,
"job_title": "Software Engineer",
"city": "Remote",
"logo": "https://pmcdeadline2.files.wordpress.com/2018/08/airbnb-logo.jpg?w=446&h=299&crop=1",
"company_name": "Airbnb",
"salary": [],
"created_at": "2018-10-22T23:18:00+0000",
"job_type": "Full Time",
"share_url":"https://ajobthing.com/",
"description": "Founded in 2008, Airbnb’s mission is to create a world where people can belong through healthy travel that is local, authentic, diverse, inclusive and sustainable. Airbnb uniquely leverages technology to economically empower millions of people around the world to unlock and monetize their spaces, passions and talents to become hospitality entrepreneurs. Airbnb’s accommodation marketplace provides access to 5+ million unique places to stay in more than 81,000 cities and 191 countries. With Experiences, Airbnb offers unprecedented access to local communities and interests through 15,000+ unique, handcrafted activities run by hosts across 1,000+ markets around the world. Airbnb’s people-to-people platform benefits all its stakeholders, including hosts, guests, employees and the communities in which it operates.",
"responsibility": "<p><ul> <li>Advocating automated testing and code quality</li> <li>Constantly monitoring, and improving the performance for all backend stacks</li> <li>Responding to alerts, pings, pages and queries</li> <li>Thinking ahead to sustain reliability and availability by building instrumentation and profiling tools, accommodating our rapidly growing user base</li> <li>Following new technologies, being eager to adapt them</li> <li>Implementing automated services, for repetitive day-to-day tasks</li> <li>Answering daily questions from users, collaborating with Support Engineers to investigate and solve support issues</li> </ul></p>",
"requirement": "<p><ul> <li>Knowledge of A Job Thing and passion for the product</li> <li>Strong computer science fundamentals, including data structures, algorithms and programming languages</li> <li>Strong knowledge of cloud architecture and application deployment</li> <li>Understanding of basic security concepts (e.g. Symmetric and Asymmetric encryption, Secure Key Exchange)</li> <li>Clear and positive communication skills in written and spoken English</li> </ul></p>"
}]}
My object model
package com.example.jobportal.models;
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class JobRecommendationsResponse{
@SerializedName("data")
private List<DataItem> data;
@SerializedName("header")
private String header;
@SerializedName("status")
private String status;
public void setData(List<DataItem> data){
this.data = data;
}
public List<DataItem> getData(){
return data;
}
public void setHeader(String header){
this.header = header;
}
public String getHeader(){
return header;
}
public void setStatus(String status){
this.status = status;
}
public String getStatus(){
return status;
}
@Override
public String toString(){
return
"JobRecommendationsResponse{" +
"data = '" + data + '\'' +
",header = '" + header + '\'' +
",status = '" + status + '\'' +
"}";
}
}
package com.example.jobportal.models;
import com.google.gson.annotations.SerializedName;
public class Salary{
@SerializedName("maximum")
private String maximum;
@SerializedName("currency")
private String currency;
@SerializedName("minimum")
private String minimum;
public void setMaximum(String maximum){
this.maximum = maximum;
}
public String getMaximum(){
return maximum;
}
public void setCurrency(String currency){
this.currency = currency;
}
public String getCurrency(){
return currency;
}
public void setMinimum(String minimum){
this.minimum = minimum;
}
public String getMinimum(){
return minimum;
}
@Override
public String toString(){
return
"Salary{" +
"maximum = '" + maximum + '\'' +
",currency = '" + currency + '\'' +
",minimum = '" + minimum + '\'' +
"}";
}
}
package com.example.jobportal.models;
import com.google.gson.annotations.SerializedName;
public class DataItem{
@SerializedName("job_type")
private String jobType;
@SerializedName("country")
private String country;
@SerializedName("city")
private String city;
@SerializedName("created_at")
private String createdAt;
@SerializedName("description")
private String description;
@SerializedName("requirement")
private String requirement;
@SerializedName("salary")
private Salary salary;
@SerializedName("responsibility")
private String responsibility;
@SerializedName("share_url")
private String shareUrl;
@SerializedName("company_name")
private String companyName;
@SerializedName("logo")
private String logo;
@SerializedName("id")
private int id;
@SerializedName("job_title")
private String jobTitle;
public void setJobType(String jobType){
this.jobType = jobType;
}
public String getJobType(){
return jobType;
}
public void setCountry(String country){
this.country = country;
}
public String getCountry(){
return country;
}
public void setCity(String city){
this.city = city;
}
public String getCity(){
return city;
}
public void setCreatedAt(String createdAt){
this.createdAt = createdAt;
}
public String getCreatedAt(){
return createdAt;
}
public void setDescription(String description){
this.description = description;
}
public String getDescription(){
return description;
}
public void setRequirement(String requirement){
this.requirement = requirement;
}
public String getRequirement(){
return requirement;
}
public void setSalary(Salary salary){
this.salary = salary;
}
public Salary getSalary(){
return salary;
}
public void setResponsibility(String responsibility){
this.responsibility = responsibility;
}
public String getResponsibility(){
return responsibility;
}
public void setShareUrl(String shareUrl){
this.shareUrl = shareUrl;
}
public String getShareUrl(){
return shareUrl;
}
public void setCompanyName(String companyName){
this.companyName = companyName;
}
public String getCompanyName(){
return companyName;
}
public void setLogo(String logo){
this.logo = logo;
}
public String getLogo(){
return logo;
}
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setJobTitle(String jobTitle){
this.jobTitle = jobTitle;
}
public String getJobTitle(){
return jobTitle;
}
@Override
public String toString(){
return
"DataItem{" +
"job_type = '" + jobType + '\'' +
",country = '" + country + '\'' +
",city = '" + city + '\'' +
",created_at = '" + createdAt + '\'' +
",description = '" + description + '\'' +
",requirement = '" + requirement + '\'' +
",salary = '" + salary + '\'' +
",responsibility = '" + responsibility + '\'' +
",share_url = '" + shareUrl + '\'' +
",company_name = '" + companyName + '\'' +
",logo = '" + logo + '\'' +
",id = '" + id + '\'' +
",job_title = '" + jobTitle + '\'' +
"}";
}
}
Api Call with retrofit
public void getJobsData() {
mProgressDialog = new ProgressDialog(getContext());
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage("Loading...");
mProgressDialog.show();
apiInterface.getJobs().enqueue(new Callback<JobRecommendationsResponse>() {
@Override
public void onResponse(Call<JobRecommendationsResponse> call, Response<JobRecommendationsResponse> response) {
mProgressDialog.dismiss();
Log.e("data", response.toString());
mProgressDialog.dismiss();
}
@Override
public void onFailure(Call<JobRecommendationsResponse> call, Throwable t) {
Log.d("Error305", t.getMessage());
mProgressDialog.dismiss();
}
});
}
My ApiInterface
package com.example.jobportal.network;
import com.example.jobportal.models.JobRecommendationsResponse;
import retrofit2.Call;
import retrofit2.http.GET;
public interface ApiServices {
@GET("/api/recommendation")
Call<JobRecommendationsResponse> getJobs();
}
My ApiClient class
package com.example.jobportal.network;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiClient {
public static final String BASE_URL = "http://private-2232a-testjobs.apiary-mock.com/";
private static Retrofit retrofit = null;
public static Retrofit jobsInfo() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
I just want to map the json object from the server to my model object and than use that model object to get the data.