0

I am new to Spring Boot and Java so excuse my ignorance. I tried Googling but they all point me to Jackson errors which is what this is but I guess I am using Jackson implicitly by using @RequestBody annotation in my controller (correct me if I am wrong). I have a Spring Boot controller that looks like this

@PostMapping(path = "/issues")
public Issue saveIssue(@RequestBody Issue issue) {
    LOG.info("Saving issue");
    return repository.save(issue);
}

The dto looks like

@Data
@NoArgsConstructor
@AllArgsConstructor
@DynamoDBTable(tableName = "")
public class Issue {

    @DynamoDBHashKey
    private String id;

    @DynamoDBAttribute
    private String type;
}

I'm using lombok for @NoArgsConstructor and @AllArgsConstructor annotations.

The issueRepository is just following simple repository pattern and just saving the issue using DynamoDBMapper. I guess this doesn't matter because the code is not getting to this point anyway. It is failing to enter the control body because of invalid params or something.

Anyway, now I am making a post request that looks something like this:

curl --location 'localhost:8080/issues' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=DC92631F992FC3EA38F7AF9C0080F856; hello=world; howdy=planet' \
--data '{
    "id: "123"
    "type": "code"
}'

I get the error

[ServerWebInputException: 400 BAD_REQUEST "Failed to read HTTP message"; nested exception is org.springframework.core.codec.DecodingException: JSON decoding error: Unrecognized field "id" (class <package>.issues.dto.Issue), not marked as ignorable; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "id" (class io.atlassian.micros.snykeventforwarder.issues.dto.Issue), not marked as ignorable (0 known properties: ])

Why are there 0 known properties when my dto class clearly has id and type defined?

streetsoldier
  • 1,259
  • 1
  • 14
  • 32

1 Answers1

0

Your curl request is missing a " after id property. But I think the problem should be about visibility. Try putting public String id; in the class just for testing purpouse. If it works, the problem Is about visibility.

Carlos Nantes
  • 1,197
  • 1
  • 12
  • 23
  • Yep. Looks like that is the issue. I made it public and the request went through. I could've sworn I had private attributes in a similar manner in a different project and it worked. What's the convention? – streetsoldier Jul 09 '23 at 00:20