1

I am fetching some data from a MYSQL database, the response I get using ARC is in the following form:

{
    "Id": 1
    -"Status": {
        "type": "Buffer"
        -"data": [1]
            0:  0
    }
    "Updated": "2016-10-25T13:15:25.000Z"
    "UserName": "Aidin"
}

In Android Studio I am trying to map this into an object with Retrofit and Serialization as follows:

@SerializedName("Id")
private int id;
@SerializedName("Status")
private boolean status;
@SerializedName("UserName")
private String name;
@SerializedName("Updated")
private Date updated;

public int getId() {
    return id;
}

public String getName() {
    return name;
}...

This works as intended for every variable except for Status. My question is, how do I do this for a Bit value from MYSQL, namely Status which seems to be an array rather than a simple bit value?

Doing

@SerializedName("Status")
private boolean status;

Does not work. I can do

@SerializedName("Status")
private LinkedTreeMap status;

And later use status.get("data") in the getter and return the bit value. But I would rather do something similar to:

@SerializedName("Status.get(\"data\")")
private boolean status;

Is this possible? What is the standard way of doing? The example I gave returns a null value.

-------------------UPDATE-----------------

After reading this thread: Which MySQL data type to use for storing boolean values

I guess my issue was more about what type to use as a boolean in MySQL. And even though there seems to be a dispute regarding appropriate boolean type, most seem to favour Tinyint. I had chosen Bit since in my mind it seemed the closest to boolean, but I guess I was wrong. Changing to Tinyint I can serialize and parse the integer value to a boolean, no problem, so my problem is solved.

However, there might come a time when I need to use a datatype which is presented as a LinkedTreeMap so I am still curious about whether or not it is possible to use something similar to:

@SerializedName("Status.get(\"data\")")
private boolean status;
Community
  • 1
  • 1
Aidin
  • 1,230
  • 2
  • 11
  • 16

0 Answers0