0
votes

I have a Python Client which can post a json Object to my Spring Boot server.

The client code looks like this:

jsonTest = {
    "room": lists
}
json_list = json.dumps(jsonTest)

requests.post('http://localhost:8082/room', json=json_list)

And the client code like this:

The Room Class:

public class Room {

   @JsonProperty("room")
   private List<List<Boolean>> roomList;

   public Room(List<List<Boolean>> roomList) {
       this.roomList = roomList;
   }

   public List<List<Boolean>> getRoomList() {
       return roomList;
   }

   public void setRoomList(List<List<Boolean>> roomList) {
       this.roomList = roomList;
   }
}

The Controller:

@RestController
public class GreetingController {

   @PostMapping(value = "/room")
   public Room room(@RequestBody Room newRoom) {
       return newRoom;
   }
}

When the post is executed i get the following error:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class de.lukas.broetje.findaway.movement.Room]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of de.luckes.findaway.movement.Room (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('{"room": [[false, false,...(a lot of content here)....., false, false]]}') at [Source: (PushbackInputStream); line: 1, column: 1]] with root cause

My Question is: Why does Jackson does not convert the JSON object?

1
Please update the question with complete error and complete jsonSmile

1 Answers

0
votes

as you already provide the below custom constructor no default, no-args constructor will be generated by Java compiler.

public Room(List<List<Boolean>> roomList) {
       this.roomList = roomList;
}

the error message says that you need to provide a default, no-args constructor in your Room class, e.g.

public Room() {
}

so add the default, no-args constructor explicitly and you should be good to go ;-)