title: SpringBoot ArrayList/JSON: add all Elements of a certain type to a list of this type
body: <p>I am trying to write a REST API to manage Invoices. As a part of this project I encounter a problem.
  I can't figure out how to add Objects of a certain type to a List of that type if the Objects are specified in a Json post request.
  The Jason contains 3 main Elements:</p>
  
  <p>An invoice number
  - A recipient (with all data required for that recipient)
  - an unknown number of articles </p>
  
  <p>and while the Controller saves the Invoice number and the recipient just fine, it doesn't save the Articles nor does it add those to the Invoice list.</p>
  
  <p>I did search Stackoverflow for this type of problem but, until now I did not find a solution.</p>
  
  <p>I also tried mapping the entire Jason Post to a map, using ObjectMapper but that is neither very hand, nor efficient if I have to map every single Input to a Map, and then search the Map in order to rebuild the Objects so I can save them to the database.</p>
  
  <p>With me having had absolutely no knowledge of Spring boot and only very basic knowledge of Java, prior to starting my work on this project, I now find myself stuck.</p>
  
  <p>In order to give you an Idea here is my controller:</p>
  
  <pre><code>@RestController
  public class RechnungController {
  
  @Autowired
  private RechnungRepository rechnung_repo;
  
  @Autowired
  private EmpfaengerRepository empf_repo;
  
  
  
  //Get Mappings
  
  
  @PostMapping ("/rechnungen")
  @ResponseBody
  public Rechnung rechnungSave (@RequestBody Rechnung r) {
  
       Rechnung r_save = rechnung_repo.save(r);
       return r_save;
  }
  
  
  
  //More get Mapping
  
  
  }
  </code></pre>
  
  <p>Here is my Invoice definition:</p>
  
  <pre><code>@Entity
  public class Rechnung  {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Long Id;
  
      private int rechnungsnummer;
  
      @OneToMany (
              cascade = CascadeType.ALL,
              orphanRemoval = true
      )
      @JoinColumn (name ="rechnungID")
      private List &lt;Artikel&gt; artikelliste = new ArrayList &lt;Artikel&gt;();//erstellt eine Liste von Artikeln vom Typ ArrayList
  
  
      @OneToOne (cascade = CascadeType.ALL)
      @JoinColumn(name= "empf", referencedColumnName = "Id")
      @RestResource
      private Empfaenger empfaenger;
  
  //Getters Setters and Constructor
  </code></pre>
  
  <p>and here is the Json i would like to post</p>
  
  <pre><code>{
  "rechnungsnummer":"02552425",
  "empfaenger": {
      "name" : "nnnnnn",
      "vorname" : "vvvvv"
      },
  
  "artikels":{
      "artikel":{
  
          "preis":"12.33"
      }
  "artikel":{
  
          "preis":"12.33"
      }
  }
  }
  </code></pre>
  
  <p>Any pointers woul be helpfull.
  Thank you.</p>