@Test
  public void test_jsonWithPersistenceContext() {

    ResetBasicData.reset();

    List<Order> orders =
        Ebean.find(Order.class)
            .fetch("customer", "id, name")
            .where()
            .eq("customer.id", 1)
            .findList();

    String json = Ebean.json().toJson(orders);

    List<Order> orders1 = Ebean.json().toList(Order.class, json);

    Customer customer = null;
    for (Order order : orders1) {
      Customer tempCustomer = order.getCustomer();
      if (customer == null) {
        customer = tempCustomer;
      } else {
        assertThat(tempCustomer).isSameAs(customer);
      }
    }
  }
  private void output(List<OrderAggregate> list) {

    for (OrderAggregate oa : list) {
      Double totalAmount = oa.getTotalAmount();
      Order order = oa.getOrder();
      Integer id = order.getId();
      Status status = order.getStatus();
      System.out.println("Order: " + id + " " + status + " total:" + totalAmount);

      Customer c = order.getCustomer();
      System.out.println("   -> customer: " + c.getId() + " " + c.getName());

      // invoke lazy loading as this property
      // has not populated originally
      // order.getOrderDate();
    }
  }
  @Test
  public void test_json_loadContext() {

    ResetBasicData.reset();

    List<Order> orders =
        Ebean.find(Order.class).select("status").fetch("customer", "id, name").findList();

    String json = Ebean.json().toJson(orders);

    JsonReadOptions options = new JsonReadOptions().setEnableLazyLoading(true);

    List<Order> orders1 = Ebean.json().toList(Order.class, json, options);

    for (Order order : orders1) {
      Customer customer = order.getCustomer();
      customer.getName();
      customer.getSmallnote();
      List<Contact> contacts = customer.getContacts();
      contacts.size();
    }
  }