Json response to grid - nested json POJO

I am currently trying to display a json response to a vaadin grid. I have pojo set up for all the objects from the response.

Currently, I am calling my OrderRoot.java class, and getting what I expected. But I have various other classes. For example a Fulfillment.java class. How can I call the specific setters and getters from that?

Example:

@Route("")
public class OrderList extends VerticalLayout {

    public OrderList(OrdersService service) {
        TextField searchField = new TextField();
            searchField.setPlaceholder("Search Serial");
            searchField.setPrefixComponent(new Icon("lumo", "search"));
            searchField.setTooltipText("Enter a serial number");

        var grid = new Grid<OrderRoot>(OrderRoot.class);
        grid.setItems(service.getOrders());
        add(searchField);
        add(grid);

    }```

Orders service class:
```java
public OrdersService(WebClient.Builder builder) {

            webClient = builder.baseUrl("https://---.---.---").build();
    }

    public OrderRoot[] getOrders() {
        return webClient
                .get()
                .uri("order/get")
                .header(auth, skuT + token)
                .retrieve()
                .bodyToMono(OrderRoot[].class).block();
    }```

If I wanted to get for instance something from the fulfillments pojo class that is under the OrderRoot class, how can I call that?

What does OrderRoot look like? Is the Fulfillment class a field on it?

public class OrderRoot {

    @JsonProperty("_id") 
    public String get_id() { 
         return this._id; } 
    public void set_id(String _id) { 
         this._id = _id; } 
    String _id;

    @JsonProperty("stash") 
    public Stash getStash() { 
         return this.stash; } 
    public void setStash(Stash stash) { 
         this.stash = stash; } 
    Stash stash;

    @JsonProperty("tags")
    public ArrayList<String> getTags() {
         return this.tags; } 
    public void setTags(ArrayList<String> tags) { 
         this.tags = tags; } 
    ArrayList<String> tags;

    @JsonProperty("store_id") 
    public String getStore_id() { 
         return this.store_id; } 
    public void setStore_id(String store_id) { 
         this.store_id = store_id; } 
    String store_id;

    @JsonProperty("order_number") 
    public String getOrder_number() { 
         return this.order_number; } 
    public void setOrder_number(String order_number) { 
         this.order_number = order_number; } 
    String order_number;

    @JsonProperty("status") 
    public String getStatus() { 
         return this.status; } 
    public void setStatus(String status) { 
         this.status = status; } 
    String status;

    @JsonProperty("channel_status") 
    public String getChannel_status() { 
         return this.channel_status; } 
    public void setChannel_status(String channel_status) { 
         this.channel_status = channel_status; } 
    String channel_status;

    @JsonProperty("batch_number") 
    public Object getBatch_number() { 
         return this.batch_number; } 
    public void setBatch_number(Object batch_number) { 
         this.batch_number = batch_number; } 
    Object batch_number;

    @JsonProperty("scans") 
    public ArrayList<Scan> getScans() { 
         return this.scans; } 
    public void setScans(ArrayList<Scan> scans) { 
         this.scans = scans; } 
    ArrayList<Scan> scans;

    @JsonProperty("log") 
    public ArrayList<Log> getLog() { 
         return this.log; } 
    public void setLog(ArrayList<Log> log) { 
         this.log = log; } 
    ArrayList<Log> log;

    @JsonProperty("items") 
    public ArrayList<Item> getItems() { 
         return this.items; } 
    public void setItems(ArrayList<Item> items) { 
         this.items = items; } 
    ArrayList<Item> items;

    @JsonProperty("fulfillments") 
    public ArrayList<Object> getFulfillments() { 
         return this.fulfillments; } 
    public void setFulfillments(ArrayList<Object> fulfillments) { 
         this.fulfillments = fulfillments; } 
    ArrayList<Object> fulfillments;

    @JsonProperty("transactions") 
    public ArrayList<Object> getTransactions() { 
         return this.transactions; } 
    public void setTransactions(ArrayList<Object> transactions) { 
         this.transactions = transactions; } 
    ArrayList<Object> transactions;

    @JsonProperty("returns") 
    public ArrayList<Return> getReturns() { 
         return this.returns; } 
    public void setReturns(ArrayList<Return> returns) { 
         this.returns = returns; } 
    ArrayList<Return> returns;

    @JsonProperty("notes") 
    public ArrayList<Object> getNotes() { 
         return this.notes; } 
    public void setNotes(ArrayList<Object> notes) { 
         this.notes = notes; } 
    ArrayList<Object> notes;
}```

I’m actually following your video you have here:
https://www.youtube.com/watch?v=-U_dDUAw_OM

This works great until I need to call different object classes

But it’s nothing to do with you, just my own knowledge level

Most likely you want to do either:

grid.setColumns(..., "fulfillment.property");

Or programmatically

grid.addColumn(order -> order.getFulfillment().getProperty()).setHeader("Fulfillment property");

I see! Let me give that a try

So how can I display different data from different pojos on the same grid?

Let me rephrase that…

I am getting data from two json responses. One response is serial numbers that have been scanned. Ex:

{
    "serial_numbers": [
        {
            "_id": "6363dcde2036d9c0953f4386",
            "store_id": "62cef3d67076781bae25ae6c",
            "order_number": "E2412",
            "item_id": "62cef3ea62c214aa81912cdc",
            "time": "2022-11-09T16:36:20.429Z",
            "serial_number": "Serial #: 866834040334760",
            "listing_id": "6900587790504",
            "variant_id": "42132807516381"
        }
    ]
}```

While this is the primary information I am looking for, I still need to get a customer name thats tied to that order number

I can get the customer’s name from OrderRoot, but i’m calling SerialRoot for the values shown above. When I get the customers name from OrderRoot how can I tie it to serialRoot

That’s not something you want to do in the grid. In your service (where you make those calls), create a DTO that only contains the information you want by pulling data from any data sets, then use those for your grid

Gotcha okay.

Any idea why my serialRoot is not displaying correctly? It is set up the same way as my orderRoot.

There seems to be a binding issue when I try retrieving any data.
There was an exception while trying to navigate to '' with the root cause java.lang.IllegalArgumentException: Can't resolve property name serial_numbers.order_number from Property set for bean com.example.demo.model.serial.SerialRoot''

Here is my serialRoot class, serialNumbers object, and how im using them:

public class SerialRoot {

    @JsonProperty("serial_numbers")
    public ArrayList<SerialNumbers> getSerial_numbers() {
        return this.serial_numbers; }
    public void setSerial_numbers(ArrayList<SerialNumbers> serial_numbers) {
        this.serial_numbers = serial_numbers; }
    ArrayList<SerialNumbers> serial_numbers;

}```

```java
public class SerialNumbers {
    @JsonProperty("_id")
    public String get_id() {
        return this._id; }
    public void set_id(String _id) {
        this._id = _id; }
    String _id;

    @JsonProperty("store_id")
    public String getStore_id() {
        return this.store_id; }
    public void setStore_id(String store_id) {
        this.store_id = store_id; }
    String store_id;

    @JsonProperty("order_number")
    public String getOrder_number() {
        return this.order_number; }
    public void setOrder_number(String order_number) {
        this.order_number = order_number; }
    String order_number;

    @JsonProperty("item_id")
    public String getItem_id() {
        return this.item_id; }
    public void setItem_id(String item_id) {
        this.item_id = item_id; }
    String item_id;

    @JsonProperty("time")
    public Date getTime() {
        return this.time; }
    public void setTime(Date time) {
        this.time = time; }
    Date time;

    @JsonProperty("serial_number")
    public String getSerial_number() {
        return this.serial_number; }
    public void setSerial_number(String serial_number) {
        this.serial_number = serial_number; }
    String serial_number;

    @JsonProperty("listing_id")
    public String getListing_id() {
        return this.listing_id; }
    public void setListing_id(String listing_id) {
        this.listing_id = listing_id; }
    String listing_id;

    @JsonProperty("variant_id")
    public String getVariant_id() {
        return this.variant_id; }
    public void setVariant_id(String variant_id) {
        this.variant_id = variant_id; }
    String variant_id;
}```

```java
public SerialRoot getSerialRoot() {
        return (SerialRoot) webClient
                .get()
                .uri("order/get_scanned_serial_numbers?start=2022-10-09T00:00:00Z&end=2022-11-10T00:00:00Z")
                .header(auth, skuT + token)
                .retrieve()
                .bodyToMono(SerialRoot.class)
                .block();
    }```
```java
public OrderList(OrdersService service) {
        TextField searchField = new TextField();
            searchField.setPlaceholder("Search Serial");
            searchField.setPrefixComponent(new Icon("lumo", "search"));
            searchField.setTooltipText("Enter a serial number");

        var gridSerial = new Grid<SerialRoot>(SerialRoot.class);
        gridSerial.setItems(service.getSerialRoot());

        add(searchField);
        add(gridSerial);
        gridSerial.setColumns();
        gridSerial.addColumn(serialRoot -> serialRoot.getSerial_numbers()).setHeader("serial numbers");
        gridSerial.addColumn("serial_numbers.order_number").setHeader("Order Number");

    }```

Serial_numbers is a list, there is no order_number in a list

Sorry, I should have updated here. I was able to fix this. I realized my mistake of trying to put a list into one single column

Yea, that has since been replaced with

gridSerial.addColumn(serialRoot -> {
            SerialNumbers serialNumbers = serialRoot.getSerial_numbers().get(0);
            return serialNumbers.getOrder_number();
                }).setHeader("Order Number");

        gridSerial.addColumn(serialRoot -> {
            SerialNumbers serialNumbers = serialRoot.getSerial_numbers().get(0);
            return serialNumbers.getSerial_number();
        }).setHeader("Serial Number");

        gridSerial.addColumn(serialRoot -> {
            SerialNumbers serialNumbers = serialRoot.getSerial_numbers().get(0);
            return serialNumbers.getTime();
        }).setHeader("Date");```

You should check that the list is not empty.

I’m having a hard time understanding how to create a DTO for these two json responses from different endpoints though. 95% of the values I need are from serialRoot, while I need a corresponding customer name to the order number from orderRoot

I was able to get the value returned in the grid properly from that

You need to create a new object with the properties and the data you want to display. One object = one row. It’s hard to give you a better answer because I don’t know what you have to display :sweat_smile:

Low Code idea:

public List getValues()
var restResult1 = do();
var restResult2 = do2();
return merge(restResult1, restResult2)