title: Flatten and De-flatten for Solr input/output
body: <p>I have lots of Java objects which have parent child relationships.</p>
  
  <p>These need to be put into Solr.</p>
  
  <p>To do that, we convert the Java object into json as follows:</p>
  
  <pre><code>{
    "employee": {
      "name" : "John",
      "address": {
        "apt": 100,
        "city": "New York",
        "country": "USA"
      },
      "vehicles": [
        {
          "name" : "Hyundai",
          "color" : "red"
        },
        {
          "name" : "Toyota",
          "color" : "black"
        }
      ]
    }
  }
  </code></pre>
  
  <p>Now since Solr does not handle this, I am flattening it out as follows:</p>
  
  <pre><code>"employee.name": "John",
  "employee.address.apt": 100,
  "employee.address.city": "New York",
  "employee.address.country": "USA",
  "employee.vehicles_0.name": "Hyundai",  // Note how arrays are being flattened
  "employee.vehicles_0.color": "red",
  "employee.vehicles_1.name": "Toyota",
  "employee.vehicles_1.color": "black",
  </code></pre>
  
  <p>It is easy to flatten, but clients of my library do not want the flattened schema when they query.</p>
  
  <p>So I need to de-flatten the above on return from Solr and convert them back to the original Java object.</p>
  
  <p>Does anyone know how this can be done?</p>
  
  <p>I am thinking of somewhat crude way of taking the flattened output from Solr (as shown above) and write a parser to put the fields back to Java objects. But this seems like lot of work. An easy way out or an existing tool would be much appreciated.</p>
  
  <p>I am using Solr 4.5.1</p>