I am have a trouble with the data format problem. I have a simple JaxB Class
@XmlRootElement(name="")
public class MyProgressResponse {
private int weight;
private long date;
/**
* Weight is treated as a Y Axis.
* @return
*/
@XmlElement(name="y")
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
/**
* This is a UTC format of a time.
* value is a number of milliseconds between a specified date and midnight January 1 1970
* This is also treated as a X-Axis
* @return
*/
@XmlElement(name="x")
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
}
And I want the REST service that fill that returns the data. like this
@GET
@Path("/my")
@Produces(MediaType.APPLICATION_JSON)
public MyProgressResponse[] getProgressResponse(){
// Get the data from DB
// Here the getDate will give me List<MyProgressResponse>
return getData().toArray(new MyProgressResponse[0]);
}
Now the JSON that I receive is like
[
{
{
"x": 1335499200000,
"y": 85
}
},
{
{
"x": 1334894400000,
"y": 84
}
},
....
]
But my requirement is to get the that does not have one extra block { }.
[
{
"x": 1335499200000,
"y": 85
},
{
"x": 1334894400000,
"y": 84
},
....
]
I want to use this in a HighChart. I can format the data in JS after i receive the data but it will get extra time and I dont want that.
Can anyone can help me in formatting the data
Thanks,
Talha Ahmed Khan
Change your return type of the method to ArrayList :
Also make your bean class implement Serializable.