Getting “error”: “Internal Error” on Postman and getting error Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

自作多情 提交于 2019-12-14 04:05:21

问题


While hitting below Softlayer rest url from Postman getting error:

"Internal Error"

And when hitting the same rest url from java code using spring restTemplate getting error as

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token.

https://api.softlayer.com/rest/v3/SoftLayer_Account/<Account-ID>/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["03/25/2017 00:00:00"]},{"name":"endDate","value": ["04/24/2017 23:59:59"]}]},"typeCode":{"operation":"RECURRING"}}}&objectMask=mask[id,items[id,recurringFee,recurringTaxAmount,oneTimeFee,oneTimeTaxAmount,description,hostName,domainName,hourlyRecurringFee,laborFee,laborTaxAmount,setupFee,setupTaxAmount,category[name],location[longName],billingItem[id,activeFlag,hourlyFlag,allowCancellationFlag,cancellationDate,orderItem[id,order[id,userRecord[username]]]]]]

回答1:


The REST URL you posted is working when the invoices don't have a lot of items. You are getting "Internal Error" because internally some invoices are returning the error "Allowed memory size of 402653184 bytes exhausted (tried to allocate 131072 bytes)", this when is added

orderItem[id,order[id,userRecord[username]]]

I got the same error with just one invoice, on my case the invoice have more than 1500 items, this is a lot of items.

Your mask is very big in depth and there are a lot of data to retrieve, for that reason Ruber recommends here Softlayer rest call giving multiple entries for invoice in json response when object filter is applied to relational properties use some programming language in order to retrieve all data you required:

Basically you need to do the following:

Step 1: Get all invoices by using SoftLayer_Account::getInvoices, based on you requirements it should be something like this:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["03/25/2017 00:00:00"]},{"name":"endDate","value": ["04/24/2017 23:59:59"]}]},"typeCode":{"operation":"RECURRING"}}}&objectMask=mask[id,createDate]

This will return the ID of all invoices, you will need this in the following step

Step 2: For each retrieved invoice use the method SoftLayer_Billing_Invoice::getItems, use resultLimits and your mask as following.

https://api.softlayer.com/rest/v3/SoftLayer_Billing_Invoice/[invoiceId]/getItems?resultLimit=100,0&objectMask=mask[id,recurringFee,recurringTaxAmount,oneTimeFee,oneTimeTaxAmount,description,hostName,domainName,hourlyRecurringFee,laborFee,laborTaxAmount,setupFee,setupTaxAmount,category[name],location[longName],billingItem[id,activeFlag,hourlyFlag,allowCancellationFlag,cancellationDate,orderItem[id,order[id,userRecord[id,username]]]]]

Change [invoiceId] by each ID you retrieved in the step 1.

On this case you need to use loops, the first loop to call SoftLayer_Billing_Invoice::getItems for each invoice and the second loop to retrieve items 100 by 100.(Instead of 100 you can set another value in resultLimit parameter)

If you set resultLimit=100,1 it will return all items between 101 to 200. I suggest to review https://sldn.softlayer.com/article/using-result-limits-softlayer-api

I recommend to use languajes like Python, Java, Go, Ruby, etc. You can see the list here https://sldn.softlayer.com/article/softlayer-api-overview.

Note: Unfortunately the object-filters feature is not supported by SoftLayer Java API.

I hope this help you.

Regards,



来源:https://stackoverflow.com/questions/43666868/getting-error-internal-error-on-postman-and-getting-error-can-not-deseriali

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!