title: Why I see that field values of Enum constants do get serialized/deserialized ? In which scenario and what exactly is not serialized in enums?
body: <p><a href="https://docs.oracle.com/javase/8/docs/platform/serialization/spec/serial-arch.html#a6469" rel="nofollow noreferrer">Serialization Specification</a> (SE8) implies that field values of enum constants are not serialized (as I read it):</p>
  
  <blockquote>
    <p>1.12 <strong>Serialization of Enum Constants</strong>
    <em>Enum constants are serialized differently</em> than ordinary serializable or externalizable objects. The serialized form of an enum constant consists solely of its name; <strong>field values of the constant are not present</strong> in the <strong><em>form</em></strong>. </p>
  </blockquote>
  
  <p>But I see that they do get serialized/deserialized.</p>
  
  <p>In code below field <code>public int x = 1234;</code> of enum constant <code>INSTANCE</code> gets serialized/deserialized in two scenarios:</p>
  
  <ol>
  <li><em>Being set only in constructor</em> (after <code>public int x = 1234;</code>, <code>setX()</code> method never called), <code>x = 1234</code> is then successfully deserialized.</li>
  <li><em>After constructor I call <code>setX(7)</code></em>, but that set value (<code>x=7</code>) is then successfully deserialized.</li>
  </ol>
  
  <p>So <strong>what exactly and under which scenario does not get serialized/deserialized in enum?</strong> <em>And what does the term "form" mean</em> (from the quote above)?</p>
  
  <pre><code>enum MyEnum1 {
  
  INSTANCE {
      public int x = 1234;
  
      public int getX() {
          return x;
      }
  
      public void setX(int x) {
          this.x = x;
      }
  };
  
  public abstract int getX();
  
  public abstract void setX(int x);
  
  }
  
  public class AAA {
  
      public static void main(String[] args) {
  
  
          MyEnum1 obj = MyEnum1.INSTANCE; 
          obj.setX(7);
          System.out.println(obj.getX());
          String fileName = "d:\\del.me";
          int bufSz = 8 * 1024;
  
          try {
              ObjectOutputStream oos = new ObjectOutputStream(
                      new BufferedOutputStream(new FileOutputStream(fileName), bufSz));
              oos.writeObject(obj);
              oos.flush();
          } catch (IOException e) {   }
  
  
          MyEnum1 obj1 = null;
          MyEnum1 obj2 = null;
          try {
              ObjectInputStream ois = new ObjectInputStream(
                      new BufferedInputStream(new FileInputStream(fileName), bufSz));
  
              ObjectInputStream ois1 = new ObjectInputStream(
                      new BufferedInputStream(new FileInputStream(fileName), bufSz));
  
              obj1 = (MyEnum1) ois.readObject();
              obj2 = (MyEnum1) ois1.readObject();
          } catch (IOException | ClassNotFoundException e) {  }
  
          // x is restored, either the one set by setX()
          // or the one just set in inline constructor (initializer) without calling setX() 
          System.out.println(obj1.getX());  // 1234 without setX(7), 7 with setX(7)
          System.out.println(obj2.getX());  // 1234 without setX(7), 7 with setX(7)
  
      }
  
  }
  </code></pre>
  
  <p>P.S. <a href="https://stackoverflow.com/questions/31432528/does-enums-field-have-to-be-serializable">This answer</a> also implies to me that fields inside enum constants don't get serialized:</p>
  
  <blockquote>
    <p>As I see it, it doesn't make sense to mark <strong>Enum's field values</strong> as
    transient or make them implement Serializable, <strong>since they'll never get
    serialized</strong>, no matter if they're marked as transient or implement
    Serializable.</p>
  </blockquote>
  
  <p>But all (non-transient) fields (at least primitive ones) <em>either within enum constant (like <code>Color { RED { fields }; }</code> )</em> <strong>or within enum but "outside" every separate constant ( <code>Color { RED { fields }; fields_for_all_constants}</code> ) do get serialized</strong>, as I see it.</p>