Spring Cloud Function JSON payload

89 views Asked by At

I'm developing a function to be deployed as AWS Lambda, in the meantime I'd like to test it locally. I don't know why, the payload got in the function is a string and not the expected object, this is the code:

@Component
public class New implements Function<Message<ApiRequestDTO>,Message<ApiResponseDTO>> {

...

    @SneakyThrows
    @Override
    public Message<ApiResponseDTO> apply(Message<ApiRequestDTO> request) {
            // 1. validate request
            validatorService.validate(request.getPayload().getDocument());

The getDocument() method throws the exception because getPayload() returns a string instead of the object.

This is the request

curl --location 'http://localhost:8080/new' \
--header 'Content-Type: application/json' \
--data '{
  "document": {
    "name": "document_name"
  }
}'

Do you know why is it happening?

Thank you

1

There are 1 answers

2
Premier On

I see, it is related to the JSON parser, basically the document_name is defined as an enum, and if the value is different from expected instead of failing it pass the input as string.