title: How to groupingBy collector to create a new field from the data?
body: <p>I have data which arrives as such (list of maps):</p>
  <pre><code>{
      “name”: “Hello”,
      &quot;source&quot;: “One”,
      &quot;status&quot;: “Good”,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  },
  {
      “name”: “Hello”,
      &quot;source&quot;: “Two”,
      &quot;status&quot;: “Good”,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  },
  {
      “name”: “Goodbye”,
      &quot;source&quot;: “Three”,
      &quot;status&quot;: “Bad”,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  },
  {
      “name”: “Goodbye”,
      &quot;source&quot;: “Four”,
      &quot;status&quot;: “Bad”,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  }
  </code></pre>
  <p>So I want to group this data by “name”, but also create a new field which collects the “source” and “status” fields into a list of objects. This would mean I'd have to map the inner data to a Java class as well (call these individual objects “sourceStatus” which I've already created a class for).</p>
  <pre><code>{
      “name”: “Hello”,
      “sourceStatuses”: [
          {
              “source”: ”One”,
              “status”: ”Good”
          },
          {
              “source”: ”Two”,
              “status”: ”Good”
          }
      ],
      “status”: “Good”,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  },
  {
      “name”: “Goodbye”,
      “sourceStatuses”: [
          {
              “source”: ”Three”,
              “status”: ”Bad”
          },
          {
              “source”: ”Four”,
              “status”: ”Bad”
          }
      ],
      “status” : “Bad,
      “date”: &quot;01-05-2021 7:35:58 PM&quot;
  }
  </code></pre>
  <p>I understand the groupingBy part can be done fairly straightforwardly with Java's Collector (<a href="https://www.baeldung.com/java-groupingby-collector" rel="nofollow noreferrer">https://www.baeldung.com/java-groupingby-collector</a>), but I'm not sure how to achieve the resultant set for my use case, where I not only create a new field but am also collecting then mapping inner data to a class.</p>
  <p>Edit: &quot;date&quot; and &quot;status&quot; are going to be the same for all items with the same &quot;name&quot;.</p>