Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm using RestAssured to test an API.
I have the following, wow can I test the post method?
{
"name": "Test",
"email": "test#email.com",
"occupation": [{
"id": 1,
"feature": {
"id": 2
},
"company": 7777,
}]
}
"Occupation" is another table, how can I on both tables?
I have tried this:
.body("{\"name\": \"test\", \"email\": \"test#email.com\", \"occupation\": {\"id\": 15, \"feature\": {\"id\": 15}", \"company\": \"7777\"}}")
But the error
"Can not deserialize instance of java.util.ArrayList out of
START_OBJECT token"
is shown.
{\"id\": 15, \"feature\": {\"id\": 15}", \"company\": \"7777\"}}"
Try using JSON array here, too!
f.e.:
[{\"id\": 1, \"feature\": {\"id\": 2}", \"company\": \"7777\"}]"
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Below is the code snippet where i need to pass the change_task objects in the query params for the POST request. how can i achieve this without adding it in the body ?
"change_task": [
{
"change_task_type": "Validation",
"planned_start_date": "2022-09-29T20:30:00",
"assignment_group": "CSRT_L2_Support",
"planned_end_date": "2022-09-30T02:30:00",
"short_description": "Test validation",
"description": "test Validation task"
},
{
"change_task_type": "Implementation",
"planned_start_date": "2022-09-29T20:30:00",
"assignment_group": "CSRT_L2_Support",
"planned_end_date": "2022-09-30T02:30:00",
"short_description": "test implementation",
"description": "test implementation task"
}
]
First of all you may ask why i should pass array of attributes with in query param, instead the content body (request body) is used for the data that is to be uploaded/downloaded to/from the server and the query parameters are used to specify the exact data requested.
So theoretically the request body should contain the data you are posting or patching and the query string, as part of the URL (a URI), it's there to identify which resource you are posting or patching.
Regarding to your specification and shared data perhaps its better to use content body instead of query string, this article may help as well.
But if yet you instead to use as query string you must know the answer is depends in framework-specific, see specific answers in here.
I am calling an external rest-API from my spring boot code which returns JSON something like this.
{
"Jack": {
"employeeId": 1,
"active": 1,
"hours": 40
},
"Ryan": {
"employeeId": 2,
"active": 1,
"hours": 40
},
"Ken": {
"employeeId": 3,
"active": 1,
"hours": 40
}
}
I am trying to convert this to java pojo using jackson and using RestTemplate to call this
I am not sure how to create java class for something like this, as the employee name keeps changing and there is No "Name key" in JSON. I can create a class for the fields employeeid,active and hours but now sure how to accommodate the employee name
Is there a way to convert these to java objects
The best way is to change the API response like "name":"Jack".It seems that it is not a good json form, isn't it?
But if you can do this,maybe this question will not exists.
The other way to convert is to convert is as Map<String,Object> and then you can get key set and you can handle the object as usual json.
Hi guys I encountered a problem on handling json on Android today. The json I got from the web service looks like the below:
e.g. from https://serviice.somewebite.com/list.json, I got this :
{
"task_id": 5,
"profile_id": 3,
"text": "{profileName} wrote {taskName}",
"created_at": "2015-08-10",
"event": "post"
},
{
"task_id": 6,
"profile_id": 2,
"text": "{profileName} wrote {taskName}",
"created_at": "2015-10-24",
"event": "post"
},
...... (and many similar entities)
the task_id is actually an id linking to other remote json, for the first entity, task_id = 5, which I should get the task json from https://serviice.somewebite.com/task/5.json, like the below:
{
"id": 5,
"name": "Clean house",
"description": "Clean every room in the house",
"state": "assigned",
}
And it is the similar way to get the profile json in the list.json file.
I have been handling json with pojo + retrofit + GSON before, but all the content are in one json, not like this.
What I want is getting all the needed jsons and show them in a listview including created_at(in list.json), task_description(in task.json), task_name(in task.json)
Currently I can only figure out one way to hanlde it. First get the list.json , and then scan the task ids and profile ids in list.json, and then get all the needed json via multiple asynchronous http requests. Seems too much boiler plate code here.
Is there an existing library/framework for this scenario? I am on Android platform using Java. Thanks a lot!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm getting following string when requested for json object.
{
"singular": "Financial Report",
"plural": "Financial Reports",
"statusId": "A",
"records": [
{
"id": 131114,
"companyId": 645588,
"userId": 5520,
"title": "Annual Report",
"typeId": "AR",
"statusId": "A",
"periodDate": new Date(1409457600000),
"isImmediate": true,
"createdDate": new Date(1419276796000),
"lastModifiedDate": new Date(1419276796000),
"releaseDate": new Date(1419276796000),
"releaseDateTimeFormatted": "Dec 22, 2014 02:33 PM",
"releaseDateFormatted": "Dec 22, 2014",
"canDistribute": true,
"wasDistributed": false,
"companyName": "Sunridge Gold Corp.",
"typeName": "Annual Report",
"name": "Annual Report - Annual Report",
"statusDescript": "Active",
"userName": "Doris Meyer",
"symbol": "SGCNF",
"primarySymbol": "SGCNF",
"primaryExchange": "OTC Link",
"isCaveatEmptor": false,
"edgarSECFiling": false
}
],
"sortOn": "releaseDate",
"sortDir": "DESC",
"totalRecords": 76165,
"pages": 3047,
"currentPage": 4,
"pageSize": 25
}
I was trying to parse it using google gson library it throwing com.google.gson.stream.MalformedJsonException
Is there any way to avoid new Date in json string above.
That is not JSON. Rather it is Javascript which includes calls to a Javascript (I think) method called newDate.
Is there any way to avoid new Date in json string above.
It depends on what is generating the not-JSON string! If you can fix that, you are good to go. Otherwise, I don't imagine that any JSON parser is going to cope with it.
For the record, the syntax for JSON is defined on the http://json.org site. If someone argues that the stuff you have shown us is real JSON, point them at the syntax ... and at the ECMA standard that that page cites as the authoritative source.
For an Android App I'm working on I need to parse json files with various informations to my App, for now the files look like this:
{
"R6":{
"Typ": "KnotenRaum",
"ID": 1,
"X-Koor": 3,
"Y-Koor": 11,
"Ebene": 0,
"Kantenliste": [ "m7" ],
"GruppenID": 1,
"Raum": {
"Nummer": "A.00.01",
"Typ": null,
"Person": null
}
},
"H107":{
"Typ": "KnotenTreppe",
"ID": 115,
"X-Koor": 7,
"Y-Koor": 3,
"Ebene": 1,
"Kantenliste": [ "h108","b1002" ],
"GruppenID": 1,
"Raum": {}
}
}
As this is my (or to be more specific our) first time using json I'm not sure if this is a "good" way of formating the file. The problem is, that I don't only have 5 or 10 objects but i guess hundreds, so i think using specifiers like "H107" is the wrong way and I should just put it all into one large array?
And second: if I put it in such an array, what is the best way to parse it to java?
I don't need class objects (at least not necessarily) as all those data will be stored in a sqlite database when the app runs for the first time.
I found some examples but mostly those only consist of one object and are a lot simpler than my resulting json file I guess.
H107 and R6 are object names?
I think this can be a array with multiple objects where "R6" can be a JSON key on object.
for example:
[
{
"name": "R6",
"Typ": "KnotenRaum",
"ID": 1,
"X-Koor": 3,
"Y-Koor": 11,
"Ebene": 0,
"Kantenliste": [
"m7"
],
"GruppenID": 1,
"Raum": {
"Nummer": "A.00.01",
"Typ": null,
"Person": null
}
},
{
"name": "H107",
"Typ": "KnotenTreppe",
"ID": 115,
"X-Koor": 7,
"Y-Koor": 3,
"Ebene": 1,
"Kantenliste": [
"h108",
"b1002"
],
"GruppenID": 1,
"Raum": {}
}
]
About objects I recommend you use an object to represent this JSON, is more readable and more easy to save on SQLite, you can use a framework like Jackson or GSON to parse this JSON automatically into objects.
I think it would be wise to store the data into Objects.
It's easier to insert objects into SQLdatabase as well as making a JSON objects array.
Andhere is a nice tutorial on the subject:
Android JSON tutorial