title: Java DTO Design - Public members
body: <p>I'm designing a DTO that will be serialized to JSON. The serializing framework kept complaining that all the members of my DTO should be public, and that the DTO should have public no-args CTOR.</p>
  
  <p>I was wondering which of these two approaches is better, in your opinion, and why:</p>
  
  <p>1) No getters/setters</p>
  
  <pre><code>public MyClass {
      public int someField;
      public String someOtherField;
  }
  </code></pre>
  
  <p>2) All getters/setters</p>
  
  <pre><code>public MyClass {
      private int someField;
      private String someOtherField;
  
      public int getSomeField() {
          return someField;
      }
  
      public String getSomeOtherField() {
          return someOtherField;
      }
  
      public void setSomeField(int someField) {
          this.someField = someField;
      }
  
      public void setSomeOtherField(String someOtherField) {
          this.someOtherField = someOtherField;
      }
  }
  </code></pre>