Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sping Data Create a Post method with List

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo everyone,

I am trying to make a new POST to add data at the same time at two tables.

{
       "fname":"Chris",
        "lname":"Ray",
       ("DataClassOne"
       ,"DataClassTwo" )
       "order" : ["grocery_store" ,"apple","1"]
     
}




I would like to fulfil my list from 2 different tables. First , I thought to make a new class DTO with the data I would like to use. Then , I make a List<DTOClass> on my CreateDTO. I did it in this way, because it is possible to have more than one product, or store at one order. But it doesn't work . Any ideas to change it ?




I thought to make a class DTO which have the data





POST Method







w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `com.demo..dto.` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('.'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.demo..dto.` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('.')
at [Source: (PushbackInputStream); line: 7, column: 16] (through reference chain: com.demo..dto.[""]->java.util.ArrayList[0])]


 
Bartender
Posts: 1944
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Eleni,
First of all, I believe your UserData or you can simply define it as User should be annotated with @Entity.


First, make sure you have Lombok plugin installed in your IDE such as IntelliJ or Eclipse.
In your pom, add
 
Himai Minh
Bartender
Posts: 1944
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you are interested in Spring data jpa application, you may want to refer to this example :https://www.journaldev.com/17034/spring-data-jpa
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic