How to publish REST service which the response contain mixed data (List/array and object)

0
I'm developing an application that will publish REST service which the response will contain list/array of 'WalletAccounts' and also the 'RestResponse'. If the response mapped to JSON structure, it should be like this: "RestResult_Wallet" : { "WalletAccounts" : [ { "acc_id" : "X001", "acc_name" : "Account Mr. X", "desc" : "xxxxx"}, { "acc_id" : "Y001", "acc_name" : "Account Mr. Y", "desc" : "yyyyy"} { "acc_id" : "Z001", "acc_name" : "Account Mr. Z", "desc" : "zzzzz"} ], "RestResponse" : { "resp_code" : "00", "resp_desc" : "SUCCESS" } }     Below the domain model that I created:   And Below is the result from what I've tried: Return the 'RestResult_Wallet', the JSON response : { "RestResponse": { "ResponseCode": "00", "ResponseDesc": "SUCCESS" } }   Return the List of entity 'WalletAccounts', the JSON response : [ { "acc_id" : "X001", "acc_name" : "Account Mr. X", "desc" : "xxxxx", "WalletAccounts_RestResult_Wallet" : { "resp_code" : "00", "resp_desc" : "SUCCESS" } }, { "acc_id" : "Y001", "acc_name" : "Account Mr. Y", "desc" : "yyyyy", "WalletAccounts_RestResult_Wallet" : { "resp_code" : "00", "resp_desc" : "SUCCESS" } }, { "acc_id" : "Z001", "acc_name" : "Account Mr. Z", "desc" : "zzzzz", "WalletAccounts_RestResult_Wallet" : { "resp_code" : "00", "resp_desc" : "SUCCESS" } } ]   Can anybody help me how to  design the entity and  REST Publish mechanism  so the result is like the JSON response that I expect? Many thanks..
asked
2 answers
1

First you need to change the association WalletAccounts_RestResult_Wallet to a reference set with the RestResult entity as owner. This causes the serializer to include those objects.

Second you need to rename this association to RestResponse in order to get the right name in JSON.

answered
0

Hi Rik Bos,

 

Thank you for your answer. Actually your suggestion almost fullfill what I expect. Below the changes I made and the result:

 

{	
	"ResponseCode": "00",
	"WalletAccountList": [
		{ "acc_id" : "X001", "acc_name" : "Account Mr. X", "desc" : "xxxxx"},
		{ "acc_id" : "Y001", "acc_name" : "Account Mr. Y", "desc" : "yyyyy"},
		{ "acc_id" : "Z001", "acc_name" : "Account Mr. Z", "desc" : "zzzzz"}
	],
	"ResponseDesc": "SUCCESS"
}

 

How to make 'ResponseCode' & 'ResponseDesc' wraped into an object 'CommonResponse' ?

answered