title: Nested Lists in Firebase
body: <p>Trying to understand how to implement nested lists in Firebase.</p>
  
  <p>Problem reducible to: a 1-to-N messaging system, where, for each message, you wish to maintain a list of users who have received, and read, that message.</p>
  
  <p>Have read <a href="https://www.firebase.com/blog/2014-04-28-best-practices-arrays-in-firebase.html" rel="nofollow noreferrer">"Best Practices for Arrays in Firebase"</a>. Trying to avoid arrays, as I have simultaneous writes, and they just don't seem a good choice here.</p>
  
  <p>Currently trying to achieve this by storing subtree's under each message, each subtree being a list of users who have received, read, or otherwise performed some action <strong><em>X</em></strong> on message <strong><em>Y</em></strong></p>
  
  <pre><code>"msgid0" : {
          "authorID": "uid0",
          "msg"     : "message text",
          "ReceivedBy": {
             uid1 : true,
             uid2 : true
           }
          "ReadBy" :    {
             uid1 : true
          }
  }
  </code></pre>
  
  <p>Question: Is it possible to put a nested datastructure like this, directly into a single object?</p>
  
  <p>I am crudely trying a test case with the following:</p>
  
  <pre><code>public class Message {
    private Long authorID;
    private String msg;
    private List&lt;String&gt; receivedBy;
    private List&lt;String&gt; readBy;
  }
  
  ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      for(DataSnapshot i: dataSnapshot.getChildren()){
        Message_FB msg = i.getValue(Message_FB.class);
      }
    }
  }
  </code></pre>
  
  <p>But it fails with:  </p>
  
  <blockquote>
    <p>Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can
    not deserialize instance of java.util.ArrayList out of START_OBJECT
    token</p>
  </blockquote>