Reputation: 19854
My ADF pipeline invokes an Azure Function (written in Java).
However, the pipeline fails with this message:
Response Content is not a valid JObject.
I've looked high and low but can't seem to find any examples of a JObject in Java.
Can anyone enlighten me as to how this may be done?
Upvotes: 2
Views: 4163
Reputation: 45
Please check your returning value. Because sometimes needed additional cast (next example on the C#):
return (ActionResult)new OkObjectResult( new {Result = response.StatusCode.ToString()});
It is not working if we return simple string or numerical value. Hope it will help you or anybody else.
Upvotes: 1
Reputation: 2378
I got around this by using the "Web" activity rather than the "Azure Function" activity.
In the web activity, you need to enter the full URL, so therefore manually need to parameterise the Azure Function base URL and the access code, but otherwise the experience is very similar and potentially more flexible.
The content of the API response is contained in the JSON property "Response". i.e.
{
"Response": "[{\"campaign_name\":\"Interactive Support\",\"campaign_end\":\"26/01/2020\"}]",
"ADFWebActivityResponseHeaders": {
"Request-Context": "appId=cid-v1:691579a9-cebe-4c49-9301-99463f150d13",
"Date": "Wed, 25 Mar 2020 17:45:27 GMT"
},
...
}
so can then be extracted using @json(activity('YourWebActivity').output.Response)
Upvotes: 0
Reputation: 2351
You simply need an JSON object returned from functions.
{
"name": "adam"
}
Unfotunately if you return array of objects, while it's proper JSON notation it will fail with Response Content is not a valid JObject.
error.
So instead of
[{
"name": "adam"
}, {
"name": "tom"
}]
Return something like
{
"items": [{
"name": "adam"
}, {
"name": "tom"
}]
}
Depending on API you might need to add
Accept: application/json
header to the request.
In java there is few options to do this one of which might be
package com.demo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/users")
public class JsonFromRestful
{
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Customer produceCustomerDetailsinJSON() {
Customer cust = new Customer();
cust.setCustNo(1);
cust.setCustName("demo");
cust.setCustCountry("poland");
return cust;
}
}
Upvotes: 6