title: How to get a hash of a Java class' structure?
body: <p>Imagine I have the following two classes:</p>
  <pre class="lang-java prettyprint-override"><code>public class A {
      private String field1;
      private B field2;
  }
  
  public class B {
      private String field3;
  }
  </code></pre>
  <p>What I want to do is use Java Reflection to get all the fields and all the subfields from class A and create a hash out of it. In this example, I would get, say, a list of Strings saying <code>[&quot;field1&quot;, &quot;field2&quot;, &quot;field3&quot;]</code>, and I would hash the entire list.</p>
  <p>In case it helps, the reason I am doing this is because I have a MongoDB collection for <code>A</code>. However, every once in a while, I add new fields to <code>A</code> or <code>B</code>, and I need to refresh the entire collection with the new fields when that happens. For this, I need to keep track, in a separate collection, of whether I have already refreshed <code>A</code>'s collection yet or not for its current structure. The easiest way would be to just hash its fields and subfields names.</p>