0

I am asking a silly questions about a pojo that will be used only for serialisation (jackson -> json), not as a business object

  • use public attributes
  • use private attributes with public getters and setters

I wonder what is the difference in this case between a simple object with public attributes and one with private attributes but with public getters and setters.

I have to stress out this object will not be used as a business object later. Only for serialization as a REST response

Mircea Stanciu
  • 3,675
  • 3
  • 34
  • 37
  • 1
    Maybe a dupe: [Public fields in a Data Transfer Object](//stackoverflow.com/q/16539238) – Tom Jun 14 '17 at 00:18
  • About the difference between public attributes and getters/setters [here is a good answer](https://stackoverflow.com/a/1568230/1759845) about the benefits of getters and setters. – BackSlash Jun 14 '17 at 00:18
  • I don't think making the objects private would give you any benefit if you're just using it for serialisation. Since you're adding public getters & setters anyway you're just doing a bunch of work for no real reason. Think it would come down to personal preference & code style, but I would probably just make it public. – Kai Jun 14 '17 at 00:29

0 Answers0