0

I've an API response which is sorted via the field provided in the payload. The API response body has a lot of parameters out of which the field on which it is sorted is a date-time field. How can I assert that the response is sorted on that date-time field?

Sample payload : URI - https://api.baseurl.com/v1/querysomething.json Payload :

{
"order_by" : "created_at"
}

Sample response :

{
"pagination":{
    page_no : 1,
    total_records : 100,
    page_size: 5,
    page_count : 20
}
"items":[
{
"id" : 123
"attr1": "attrvalue"
"attr2::[
   {},{},{}
],
.
.
.
.
.
.
"created_at": "2022-11-02T10:48:04.148Z"
},
{
"id" : 1234
"attr1": "attrvalue"
"attr2::[
   {},{},{}
],
.
.
.
.
.
.
"created_at": "2022-11-01T11:45:04.148Z"
}
]
}

I've already gone through the solutions mentioned here and here and I don't think the solution applies here. Please correct me if I am wrong in understanding this.

demouser123
  • 4,108
  • 9
  • 50
  • 82
  • One way to do it is to extract all dates, stored in List and then compare dates using something like this: boolean isAfter = LocalDate.parse("2016-06-12") .isAfter(LocalDate.parse("2016-06-11")); – Alex Karamfilov Nov 10 '22 at 13:06
  • Also check this: https://stackoverflow.com/questions/5927109/sort-objects-in-arraylist-by-date – Alex Karamfilov Nov 10 '22 at 13:27

0 Answers0