V1 Kr V1 Kr - 3 months ago 12
JSON Question

JSON - no Response data, using Retrofit and Gson

Issue: Request is being done(hits are increasing) but there is no Response.
What I did so far:
- I rechecked all the namings and type
- Went through all similar StackOverflow questions

Log:

Attempted to deserialize a java.lang.Class. Forgot to register a type adapter?


Json data:

{
"total": 1,
"error": "",
"train": [
{
"travel_time": "21:15",
"from": {
"name": "GORAKHPUR",
"code": "GKP"
},
"number": "12591",
"src_departure_time": "06:35",
"to": {
"name": "NAGPUR",
"code": "NGP"
},
"classes": [
{
"available": "N",
"class-code": "2S"
},
{
"available": "Y",
"class-code": "3A"
},
{
"available": "N",
"class-code": "CC"
},
{
"available": "N",
"class-code": "FC"
},
{
"available": "N",
"class-code": "1A"
},
{
"available": "Y",
"class-code": "SL"
},
{
"available": "N",
"class-code": "3E"
},
{
"available": "Y",
"class-code": "2A"
}
],
"days": [
{
"runs": "N",
"day-code": "MON"
},
{
"runs": "N",
"day-code": "TUE"
},
{
"runs": "N",
"day-code": "WED"
},
{
"runs": "N",
"day-code": "THU"
},
{
"runs": "N",
"day-code": "FRI"
},
{
"runs": "Y",
"day-code": "SAT"
},
{
"runs": "N",
"day-code": "SUN"
}
],
"no": 1,
"name": "GKP-SBC EXP",
"dest_arrival_time": "03:50"
}
],
"response_code": 200
}


TrainFromToResponse.java:

package com.vyshnav.trainfromto.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class TrainFromToResponse {

private int total;
private String error;
private List<Train> train = new ArrayList<Train>();
private int response_code;


/**
*
* @return
* The train
*/
public List<Train> getTrain() {
return train;
}

/**
*
* @param train
* The train
*/
public void setTrain(List<Train> train) {
this.train = train;
}

/**
*
* @return
* The responseCode
*/
public int getResponseCode() {
return response_code;
}

/**
*
* @param responseCode
* The response_code
*/
public void setResponseCode(int responseCode) {
this.response_code = responseCode;
}

/**
*
* @return
* The total
*/
public int getTotal() {
return total;
}

/**
*
* @param total
* The total
*/
public void setTotal(int total) {
this.total = total;
}

/**
*
* @return
* The error
*/
public String getError() {
return error;
}

/**
*
* @param error
* The error
*/
public void setError(String error) {
this.error = error;
}
}


Train.java:

package com.vyshnav.trainfromto.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class Train {

private List<Days> days = new ArrayList<Days>();
private int no;
private String number;
private String dest_arrival_time;
private To to;
private From from;
private List<Class> classes = new ArrayList<Class>();
private String name;
private String src_departure_time;
private String travel_time;


/**
*
* @return
* The days
*/
public List<Days> getDays() {
return days;
}

/**
*
* @param days
* The days
*/
public void setDays(List<Days> days) {
this.days = days;
}

/**
*
* @return
* The no
*/
public int getNo() {
return no;
}

/**
*
* @param no
* The no
*/
public void setNo(int no) {
this.no = no;
}

/**
*
* @return
* The number
*/
public String getNumber() {
return number;
}

/**
*
* @param number
* The number
*/
public void setNumber(String number) {
this.number = number;
}

/**
*
* @return
* The destArrivalTime
*/
public String getDestArrivalTime() {
return dest_arrival_time;
}

/**
*
* @param destArrivalTime
* The dest_arrival_time
*/
public void setDestArrivalTime(String destArrivalTime) {
this.dest_arrival_time = destArrivalTime;
}

/**
*
* @return
* The to
*/
public To getTo() {
return to;
}

/**
*
* @param to
* The to
*/
public void setTo(To to) {
this.to = to;
}

/**
*
* @return
* The from
*/
public From getFrom() {
return from;
}

/**
*
* @param from
* The from
*/
public void setFrom(From from) {
this.from = from;
}

/**
*
* @return
* The classes
*/
public List<Class> getClasses() {
return classes;
}

/**
*
* @param classes
* The classes
*/
public void setClasses(List<Class> classes) {
this.classes = classes;
}

/**
*
* @return
* The name
*/
public String getName() {
return name;
}

/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}

/**
*
* @return
* The srcDepartureTime
*/
public String getSrcDepartureTime() {
return src_departure_time;
}

/**
*
* @param srcDepartureTime
* The src_departure_time
*/
public void setSrcDepartureTime(String srcDepartureTime) {
this.src_departure_time = srcDepartureTime;
}

/**
*
* @return
* The travelTime
*/
public String getTravelTime() {
return travel_time;
}

/**
*
* @param travelTime
* The travel_time
*/
public void setTravelTime(String travelTime) {
this.travel_time = travelTime;
}
}


From.java:

package com.vyshnav.trainfromto.model;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class From {

private String code;
private String name;


/**
*
* @return
* The code
*/
public String getCode() {
return code;
}

/**
*
* @param code
* The code
*/
public void setCode(String code) {
this.code = code;
}

/**
*
* @return
* The name
*/
public String getName() {
return name;
}

/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
}


To.java:

package com.vyshnav.trainfromto.model;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class To {

private String code;
private String name;

/**
*
* @return
* The code
*/
public String getCode() {
return code;
}

/**
*
* @param code
* The code
*/
public void setCode(String code) {
this.code = code;
}

/**
*
* @return
* The name
*/
public String getName() {
return name;
}

/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
}


Classes:

package com.vyshnav.trainfromto.model;

import com.google.gson.annotations.SerializedName;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class Classes {

private String available;
@SerializedName("class-code")
private String classCode;


/**
*
* @return
* The available
*/
public String getAvailable() {
return available;
}

/**
*
* @param available
* The available
*/
public void setAvailable(String available) {
this.available = available;
}

/**
*
* @return
* The classCode
*/
public String getClassCode() {
return classCode;
}

/**
*
* @param classCode
* The class-code
*/
public void setClassCode(String classCode) {
this.classCode = classCode;
}
}


Days:

package com.vyshnav.trainfromto.model;

import com.google.gson.annotations.SerializedName;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class Days {

private String runs;
@SerializedName("day-code")
private String dayCode;


/**
*
* @return
* The runs
*/
public String getRuns() {
return runs;
}

/**
*
* @param runs
* The runs
*/
public void setRuns(String runs) {
this.runs = runs;
}

/**
*
* @return
* The dayCode
*/
public String getDayCode() {
return dayCode;
}

/**
*
* @param dayCode
* The day-code
*/
public void setDayCode(String dayCode) {
this.dayCode = dayCode;
}
}

Answer

You are referenced java.lang.Class instead of com.vyshnav.trainfromto.model.Classes on this line:

private List<Class> classes = new ArrayList<Class>();