@Test
public void deepNestingToMap() {

    ODocument doc = new ODocument();
    doc.field(DocumentUtil.ORIENTDB_PRIMARY_KEY, "client-assigned-id");
    List<ODocument> detail = new ArrayList<ODocument>();
    List<ODocument> addresses = new ArrayList<ODocument>();
    ODocument status1 = new ODocument("inventory", 10);
    ODocument status2 = new ODocument("inventory", 20);
    addresses.add(new ODocument().field("street", "Main st.").field("city", "San Franciso").field("status", status1, OType.EMBEDDED));
    addresses.add(new ODocument().field("street", "Wall st.").field("city", "New York").field("status", status2, OType.EMBEDDED));
    detail.add(new ODocument().field("locations", addresses, OType.EMBEDDED));
    
    doc.field("widget", new ODocument().field("name","widget-a").field("detail", detail), OType.EMBEDDED);
    
    Map result = DocumentUtil.toMap(doc);
    
    assertThat(result).includes(
            entry(DocumentUtil.TAG_ID, "client-assigned-id"),
            entry(DocumentUtil.TAG_REV, "0"));
    Map resultWidgets = (Map) result;
    
    Map resultWidget = (Map) resultWidgets.get("widget");
    List resultDetails = (List) resultWidget.get("detail");
    Map resultDetail1 = (Map) resultDetails.get(0);
    List resultLocations = (List) resultDetail1.get("locations");
    Map resultAddress2 = (Map) resultLocations.get(1);
    System.out.println(resultAddress2);
    Map resultStatus = (Map) resultAddress2.get("status");
    Integer resultInventory = (Integer) resultStatus.get("inventory");
    assertEquals(resultInventory.intValue(), 20);
}