flexjson.JSONException Don't know how to bind

558 views Asked by At

My android application use flexjson library to deserialize json data string received from server via RESTfull webservice. But when deserialize i get error.

flexjson.JSONException: [ data.status ]: Don't know how to bind Clock_in into class wfa.com.tma.wfa.type.TimeClockStatus. You might need to use an ObjectFactory instead of a plain class.

this is my String

{
  "data":
     {
       "todayShift":
           {
              "startTime":"1970-01-01T13:30:00Z",
              "endTime":"1970-01-02T00:00:00Z",
              "office":
                    {
                       "id":1,"name":"Location Test 1"
                    }
          },
       "currentTime":"2017-10-12T07:47:11Z",
       "status":"Clock_in",
       "latestTime":"2017-10-12T07:46:13Z",
       "latestOffice":{"id":1,"name":"Location Test 1"}},
       "meta":{"type":"TimeClockDto"}
 }

the DTO of this String

public class TimeClockDto implements Serializable
{
    private static final long serialVersionUID = 1L;
    private TodayShiftDto todayShift;
    private String currentTime;
    private TimeClockStatus status;
    private String latestTime;
    private BaseLocationDto latestOffice;
    public TimeClockDto(TodayShiftDto todayShift, String currentTime, 
    TimeClockStatus status, String latestClockInTime,
                        BaseLocationDto latestOffice)
    {
        this.todayShift = todayShift;
        this.currentTime = currentTime;
        this.status = status;
        this.latestTime = latestClockInTime;
        this.latestOffice = latestOffice;
    }
    //getter, setter
}

`and the deserialize code

and the enum class

public enum TimeClockStatus
{
Clock_in, Clock_out;
}
1

There are 1 answers

0
Tung Vo On BEST ANSWER

I have solve this problem by using EnumObjectFactory

TimeClockDto result = new JSONDeserializer<TimeClockDto>
                        .use("data", TimeClockDto.class)
                        .use("data.todayShift", TodayShiftDto.class)
                        .use("data.status", new EnumObjectFactory())
                        .use("data.latestOffice", BaseLocationDto.class)
                        .deserialize(param.getResult(),TimeClockDto.class);