Retrofit: Expected BEGIN_ARRAY but was BEGIN_OBJECT - retrofit2

As I do for the get object "services" ?
{
"success": "true",
"code": "200",
"message": "The operation was successful",
"data": {
"hairdressers": [
{
"name": "Jason Grant",
"image_profile": "http:\/\/www.kbapi.co\/images\/header\/3.png",
"open": "09:00:00",
"close": "15:00:00",
"id": "2",
"id_saloon": "4",
"services": [
{
"name": "Corte",
"price": "8000",
"image": "http:\/\/www.kbapi.co\/images\/header\/1.png",
"time": "01:00:00",
"type": "W",
"saloon_id": "4",
"service_id": "3"
},
{
"name": "Corte",
"price": "8000",
"image": "http:\/\/www.kbapi.co\/images\/header\/1.png",
"time": "01:00:00",
"type": "C",
"saloon_id": "4",
"service_id": "4"
},
{
"name": "Corte",
"price": "9000",
"image": "http:\/\/www.kbapi.co\/images\/header\/1.png",
"time": "01:00:00",
"type": "O",
"saloon_id": "4",
"service_id": "5"
}
]
},
{
"name": "Herbert Davis",
"image_profile": "http:\/\/www.kbapi.co\/images\/header\/4.png",
"open": "10:00:00",
"close": "16:00:00",
"id": "3",
"id_saloon": "4",
"services": []
}
]
}
}

The error occurs because you're telling Retrofit that you're expecting a JSONArray but instead you're getting a JSON object. I took a quick look at the result that you're using and it looks like it returns a JSON object and the returned object then contains the list you're interested in accessing. I can help you further if you post your GET call.

You should wrap your list of objects with one more java class
public class Response {
private boolean success;
private int code;
private String message;
private List<Data> data;
}
public class Data {
private List<Hairdresser> hairdressers = new ArrayList<Hairdresser>();
}
to generate this objects automatically you can use service like this one

Related

Nodejs Customized JSON from lucid response

I have the following result set from the database, The result is an array of objects but I want it to look alike a nested objects as shown in the example.
[
{
"id": 4,
"entity": "dashboard",
"key": "message",
"value": "How to watch Netflix with XXX on Android?",
"locale": "en",
"created_at": "2022-10-25T14:41:38.000+05:00",
"updated_at": "2022-10-25T14:41:38.000+05:00"
},
{
"id": 9,
"entity": "in_survey",
"key": "content",
"value": "",
"locale": "en",
"created_at": "2022-10-25T14:41:38.000+05:00",
"updated_at": "2022-10-25T14:41:38.000+05:00"
}
]
Need a response like this from the above JSON
{
"dashboard": {
"message": "How to watch XYZ on Android?",
},
"in_survey": {
"content": ""
}
}

Issue on converting EnrichedActivity to String

I need to convert EnrichedActivity to String as I use stream-java:3.2.4 in a Flutter application.
I get EnrichedActivity list like this:
val list : List<EnrichedActivity> = client.flatFeed("user").getEnrichedActivities(EnrichmentFlags()
.withOwnReactions()
.withRecentReactions()
.withReactionCounts()).get()
Then I try to convert the list like this:
val resultString = ObjectMapper()
.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
.writeValueAsString(list)
But some fields are erased by FasterXml-jackson (v2.9.6).
Isn't this the correct way to convert an EnrichedActivity list to String?
Note 1- Original EnrichedActivity list:
0 = {EnrichedActivity#15673}
"EnrichedActivity{id=5e02d656-27ef-11eb-88f9-128a130028af,
actor=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, verb=post,
object=Data{id=b0e249e9-8695-4161-bb24-d3980da4cdeb, data={}},
foreignID=, target=Data{id=, data={}}, time=Mon Nov 16 12:37:39
GMT+03:00 2020, origin=null, to=null, score=null,
ownReactions={like=[Reaction{id=4186ea14-f3e5-4368-8a91-eafc12e3045b,
appID=null, kind=like, userID=RqO5ns7mrYfvain3ETQpdPgIQZz1,
activityID=5e02d656-27ef-11eb-88f9-128a130028af, parent=,
ownChildren=null, latestChildren={}, childrenCounts={},
userData=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, activityData={},
extra={updated_at=2020-11-16T09:39:25.088760Z,
created_at=2020-11-16T09:39:25.088760Z}}]},
latestReactions={like=[Reaction{id=4186ea14-f3e5-4368-8a91-eafc12"
1= {EnrichedActivity#15674}
"EnrichedActivity{id=6f18988b-277d-11eb-96e2-1254437355c5,
actor=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, verb=post,
object=Data{id=11f22b84-5168-452e-b098-c9f60818d6b2, data={}},
foreignID=, target=Data{id=, data={}}, time=Sun Nov 15 23:02:05
GMT+03:00 2020, origin=null, to=null, score=null,
ownReactions={like=[Reaction{id=63471022-3e44-4d44-ad3d-6104d96a0843,
appID=null, kind=like, userID=RqO5ns7mrYfvain3ETQpdPgIQZz1,
activityID=6f18988b-277d-11eb-96e2-1254437355c5, parent=,
ownChildren=null, latestChildren={}, childrenCounts={},
userData=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, activityData={},
extra={updated_at=2020-11-16T09:31:16.925141Z,
created_at=2020-11-16T09:31:16.925141Z}},
Reaction{id=9c7e0401-6ed0-47a8-b239-2669786e3340, appID=null, kind="
Note 2- The serialized form of the list above:
[ { "actor": { "id": "RqO5ns7mrYfvain3ETQpdPgIQZz1", "updated_at":
"2020-11-11T22:46:38.568116Z", "name": "RqO5ns7mrYfvain3ETQpdPgIQZz1",
"created_at": "2020-11-11T22:46:38.568116Z" }, "id":
"5e02d656-27ef-11eb-88f9-128a130028af", "object": { "id":
"b0e249e9-8695-4161-bb24-d3980da4cdeb" }, "target": { "id": "" },
"time": "2020-11-16T09:37:39.284", "verb": "post", "foreign_id": "",
"message": "test2", "latest_reactions_extra": { "like": { "next": "" }
} }, { "actor": { "id": "RqO5ns7mrYfvain3ETQpdPgIQZz1", "updated_at":
"2020-11-11T22:46:38.568116Z", "name": "RqO5ns7mrYfvain3ETQpdPgIQZz1",
"created_at": "2020-11-11T22:46:38.568116Z" }, "id":
"6f18988b-277d-11eb-96e2-1254437355c5", "object": { "id":
"11f22b84-5168-452e-b098-c9f60818d6b2" }, "target": { "id": "" },
"time": "2020-11-15T20:02:05.321", "verb": "post", "foreign_id": "",
"message": "Test", "latest_reactions_extra": { "like": { "next":
"https://stream-io-api.com/api/v1.0/reaction/activity_id/6f18988b-277d-11eb-96e2-1254437355c5/like/?id_lt=4fa212db-0125-4b4e-9a77-04e4940ec64a&limit=5&withOwnChildren=false"
} } } ]

Azure API Set-body JSON to JSON covert

The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject

Jira Python Keyerror on issue links

I have a script which goes to fetch info via Jira API then its doing some comparison but i'm getting the following error :
Error :
"errorMessage": "'outwardIssue'"
"errorType": "KeyError"
JSON format:
"issuelinks": [
{
"id": "1255",
"self": "https://jiraurl/rest/api/2/issueLink/0000",
"type": {
"id": "10030",
"name": "Arises ",
"inward": "gives rise to",
"outward": "arises from",
"self": "https://jiraurl/rest/api/2/issueLinkType/0000"
},
"outwardIssue": {
"id": "1251575",
"key": "temp-511",
"self": "https://jiraurl/rest/api/2/issue/0000",
"fields": {
"summary": "a summary",
"status": {
"self": "https://jiraurl/rest/api/2/status/6",
"description": "test",
"iconUrl": "",
"name": "Closed",
"id": "6",
"statusCategory": {
"self": "https://jiraurl/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
"issuetype": {
"self": "https://jiraurl/rest/api/2/issuetype/20",
"id": "20",
"description": "Problem ",
"iconUrl": "https://jiraurl/images/icons/issuetypes/documentation.png",
"name": "Problem",
"subtask": false
}
}
}
}
]
Python Statement where we believe the issue is:
if (problem['fields']['issuelinks'][0]['outwardIssue']) and (problem['fields']['issuelinks'][0]['type']['outward'] == "arises from"):
isitanissue = False
I cant see why its stuck on'outwardIssue' ?
try this:
issue = jira.issue("XX)
if (issue.raw['fields']['issuelinks'][0]['outwardIssue']) and (issue.raw['fields']['issuelinks'][0]['type']['outward'] == "arises from"): isitanissue = False

how to fetch data from two collection in arangodb

my project backend is arangodb. I have two collections named "test" and "demo". i need to fetch data from both these tables. my data is like this:
test
[
{
"firstName": "abc",
"lastName": "pqr",
"company": "abc Industries",
"id": "1234"
},
{
"firstName": "xyz",
"lastName": "qwe",
"company": "xyz Industries",
"id": "5678"
}
]
demo
[
{
"clientId": "1234",
"subject": "test",
"message": "testing",
"priority": "High",
"status": "closed",
"id": "111111"
},
{
"clientId": "1234",
"subject": "hiii",
"message": "demo",
"priority": "High",
"status": "closed",
"id": "222222"
},
]
in this id of the test is same as clientid of the demo. i need to select data from the table that is data of the client "1234". how can i implement this using AQL(arango query language). i am new to arango. any suggestion will highly appreciable.
You can do this with joins or subqueries.
A solution with a subqueries would look like:
FOR t IN test
FILTER t.id == #client
RETURN {
test: t,
demo: (FOR d IN demo
FILTER d.clientId == #client
RETURN d)
}
The #client is a bind parameter which contains your value 1234.
The result is:
[
{
"test": {
"_key": "140306",
"_id": "test/140306",
"_rev": "_Urbgapq---",
"company": "abc Industries",
"firstName": "abc",
"id": "1234",
"lastName": "pqr"
},
"demo": [
{
"_key": "140233",
"_id": "demo/140233",
"_rev": "_UrbfyAm---",
"clientId": "1234",
"id": "222222",
"message": "demo",
"priority": "High",
"status": "closed",
"subject": "hiii"
},
{
"_key": "140200",
"_id": "demo/140200",
"_rev": "_UrbfjfG---",
"clientId": "1234",
"id": "111111",
"message": "testing",
"priority": "High",
"status": "closed",
"subject": "test"
}
]
}
]
For t in test
for d in demo
filter t.id == d.clientId
filter t.id == #client
return {t,d}
FOR collection IN [test,demo]
FOR x IN collection
RETURN x

Resources