Error while trying to deserialize the Amazon Textract output - system.text.json

I am defining the OutputConfig property of the StartDocumentTextDetectionRequest in order to save the Amazon Textract json result in my own custom bucket.
The problem that I have is that I try to deserialize the json file to the DetectDocumentTextResponse type, I am getting the following exception:
System.Text.Json.JsonException: 'The JSON value could not be converted to Amazon.Textract.BlockType. Path: $.Blocks[0].BlockType | LineNumber: 0 | BytePositionInLine: 30.'
How should I do to make the deserialization to work properly, because the json file is valid.

Related

Invalid request body error when sending json string as data to an external api using CL_HTTP_CLIENT

We are facing an issue while sending json data to an external api using CL_HTTP_CLIENT.
The JSON data is produced using '/ui2/cl_json=>serialize( data = ls_body compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case )' .
when sending this JSON as data the the external api returns status 400 with response as
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0." } .
we also stringyfied this JSON Data in backend as it might be due to parsing error but it didnt work.
The same stringyfied data tried to send through browser console using ajax and it did worked without any issue.
could any any one tell us how to handle this json object and send this to external api using CL_HTTP_CLIENT.
Note : JSON STRING is deeply nested .
Thanks in advance..
You can use request catcher service for getting SAP output.
Then check your output has valid json.
Check external api with rest tool like postman or SoapUI. Every developer not track guidliness may be external api has limitations.
The issue was with the unicodes in the string.
these were not accepted by the external api so removed from the string and sent to api and it did worked.
Thanks for You suggestion.

Jackson InvalidFormatException: Cannot deserialize value of type `java.util.UUID` from String

Am using Spring boot with a Rest Controller. I have a #PostMapping with a #RequestBody having object that has id of type UUID. When I am trying to test my post request from Postman I get the following error.
JSON parse error:
Cannot deserialize value of type java.util.UUID from String "4be4bd08cfdf407484f6a04131790949": UUID has to be represented by standard 36-char representation; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.util.UUID from String "4be4bd08cfdf407484f6a04131790949": UUID has to be represented by standard 36-char representation
I read in some post that talked about invalidFormatException but with a different data type that need to write some kind of Adapter. How can I resolve this for the UUID? Thanks in advance for your input.
#PostMapping(value = "/save_order")
#ResponseStatus(HttpStatus.CREATED)
public void postOrder(#RequestBody Order order) {
...
public class Order {
#Id
private UUID dstId;
....
Never mind, I searched around and was able to resolve the issue. Below is the solution.
So basically the solution was to remove the ID from the JSON that I was using for the request body. The Json that I was using earlier had dstId as the first key, removing it resolved my error.
{
"dstId":"4be4bd08cfdf407484f6a04131790949",
...
}
Also I realized that the root cause was that the data I was using above is not a valid UUID. Using a valid UUID in it's place worked, for example
"dstId": "110841e3-e6fb-4191-8fd8-5674a5107c33
The post that helped me to figure out Spring Boot JSON parse error: Cannot deserialize error

Accessing FlowFile content in NIFI PutS3Object Processor

I am new to NIFI and want to push data from Kafka to an S3 bucket. I am using the PutS3Object processor and can push data to S3 if I hard code the Bucket value as mphdf/orderEvent, but I want to specify the buckets based on a field in the content of the FlowFile, which is in Json. So, if the Json content is this {"menu": {"type": "file","value": "File"}}, can I have the value for the Bucket property as as mphdf/$.menu.type? I have tried to do this and get the error below. I want to know if there is a way to access the FlowFile content with the PutS3Object processor and make Bucket names configurable or will I have to build my own processor?
ERROR [Timer-Driven Process Thread-10]
o.a.nifi.processors.aws.s3.PutS3Object
com.amazonaws.services.s3.model.AmazonS3Exception: The XML you
provided was not well-formed or did not validate against our
published schema (Service: Amazon S3; Status Code: 400; Error Code:
MalformedXML; Request ID: 77DF07828CBA0E5F)
I believe what you want to do is use an EvaluateJSONPath processor, which evaluates arbitrary JSONPath expressions against the JSON content and extracts the results to flowfile attributes. You can then reference the flowfile attribute using NiFi Expression Language in the PutS3Object configuration (see your first property Object Key which references ${filename}). In this way, you would evaluate $.menu.type and store it into an attribute menuType in the EvaluateJSONPath processor, then in PutS3Object you would have Bucket be mphdf/${menuType}.
You might have to play around with it a bit but off the top of my head I think that should work.

AFNetworking JSON text did not start with array or object and option to allow fragments not set

I am getting response for my web-service like this when I run it in browser: IN.Tags.Share.handleCount({"count":5,"fCnt":"5","fCntPlusOne":"6","url":"http:\\myWebService?postid=24"});
But when I use afnetworking code to get response it gives error like:
Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set.
how can I get response like only :
({"count":5,"fCnt":"5","fCntPlusOne":"6","url":"http:\\myWebService?postid=24"})

WCF error handler

I have created a web service based on
http://blogs.msdn.com/b/endpoint/archive/2010/01/06/introducing-wcf-webhttp-services-in-net-4.aspx
i am trying to add an error hadler based on
http://www.codeproject.com/KB/WCF/WCFErrorHandling.aspx
I have given
In web.config such that i am getting
result of a [OperationContract]
either as xml or as Json based on the request content type header.
But when an error occurs the error is returned only as XML
It is not returning error as JSON
Wat can i do to get error as JSON?
You need to implement IErrorHandler and write a ProvideFault method to output as WebContentFormat.Json
you can get all the details of how to do it here:
http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/
http://blog.wadolabs.com/2009/03/wcf-exception-handling-with-ierrorhandler/