We help IT Professionals succeed at work.
Get Started
Private
Troubleshooting Question

Java modifying JsonArray to match model class

zolf
zolf asked
on
39 Views
Last Modified: 2020-11-21
Hello there,

I have this result returned from the db and my code looks, like so
final List<JsonObject> rows = ar.result().getRows();
final JsonArray result = new JsonArray();
rows.forEach(result::add);
gotSupplierRawMaterialID.complete(result);
LOG.debug("result " + rows);
result [{"id":72,"receiptno":"908","dateofentry":20200819,"supplier":10,"rawmaterialid":14,"quantity":20},{"id":72,"receiptno":"908","dateofentry":20200819,"supplier":10,"rawmaterialid":11,"quantity":80}]
I want to modify the result to match my model class which is like so,

public class SendToCompanyFromSupplier
{
private Integer id;
   private Integer entrydate;
    private String receiptno;
    private Integer warehouse;
    private Integer supplier;
    private ArrayList<Rawmaterialwh> rawmaterialwh;
}
and
public class Rawmaterialwh
{
   Integer rawmaterialid;
   Integer qty;
}
 and return the result like so

{
  "id" : 72,
  "entrydate" : 20200819,
  "receiptno" : "908",
  "warehouse" : 0,
  "supplier" : 10,
  "rawmaterialwh" : [ {
    "rawmaterialid" : 14,
    "qty" : 20
  }, {
    "rawmaterialid" : 11,
    "qty" : 80
  }, {
    "rawmaterialid" : 18,
    "qty" : 60
  } ]
}

Thanks!!

Comment
Watch Question
Database Administrator / Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE