Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-884

Lombok generated constructor not found for deserialization on POST requests

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5.2 (Hopper SR2), 2.5.3 (Hopper SR3)
    • Fix Version/s: None
    • Component/s: Infrastructure
    • Labels:
      None
    • Environment:
      Latest Java 8, Spring Boot 1.4.0

      Description

      With Spring Boot 1.3.7 the following is working, with Spring Boot 1.4.0 not anymore:
      You find all the examples in this report at https://github.com/toedter/chatty/
      Branches:
      master -> Spring Boot 1.3.7 => working
      Spring-Boot-1.4.0 -> Spring Boot 1.4.0 => not working

      Consider 2 REST resources with repositories: User and ChatMessage
      ChatMessage has a relation to user:
      @ManyToOne
      private User author;

      With Spring Boot 1.3.7 it was possible to create a new ChatMessage including a relation to an existing user with one POST request, when http://localhost:8080/api/users/toedter_k points to a valid User resource :

      curl 'http://localhost:8080/api/messages' -i -X POST -H 'Content-Type: application/hal+json' -d '{"author":"http://localhost:8080/api/users/toedter_k","text":"Hello!"}'
      

      This call gives the following error when using Spring Boot 1.4.0:
      o.s.d.r.w.RepositoryRestExceptionHandler : Could not read document: Can not construct instance of com.toedter.chatty.server.boot.user.User: no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/api/users/toedter_k')

      You find the corresponding test (Spring Restdocs) at
      https://github.com/toedter/chatty/blob/master/subprojects/com.toedter.chatty.server.boot/src/test/java/com/toedter/chatty/server/boot/ApiDocumentation.java

          @Test
          public void messagesCreateExample() throws Exception {
              Map<String, String> user = new HashMap<String, String>();
              user.put("id", "toedter_k");
              user.put("fullName", "toedter_k");
              user.put("email", "kai@toedter.com");
      
              String userLocation = this.mockMvc
                      .perform(
                              post("/api/users").contentType(MediaTypes.HAL_JSON).content(
                                      this.objectMapper.writeValueAsString(user)))
                      .andExpect(status().isCreated()).andReturn().getResponse()
                      .getHeader("Location");
      
              Map<String, Object> chatMessage = new HashMap<String, Object>();
              chatMessage.put("text", "Hello!");
              chatMessage.put("author", userLocation);
      
              this.mockMvc.perform(
                      post("/api/messages").contentType(MediaTypes.HAL_JSON).content(
                              this.objectMapper.writeValueAsString(chatMessage))).andExpect(
                      status().isCreated())
                      .andDo(document("messages-create-example",
                              requestFields(
                                      fieldWithPath("text").description("The text of the chat message"),
                                      fieldWithPath("author").description("The author of the chat message. This must be the URL to an existing user resource."))));
          }
      

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              toedter_k Kai Tödter
              Last updater:
              Robert Rackl
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: