0

Reading some articles, it is best to have POJO object to do JSON or XML serialization. I am wondering whether POJO can have construtors or methods?

user496949
  • 83,087
  • 147
  • 309
  • 426

1 Answers1

3

"POJO" is a terrible name, but basically, yes, a Javabean class representing an entity would be extremely helpful in doing the JSON or XML serialization since there are so many API's out which understands Javabeans and can convert between them and the desired format in a single code line. Last but not least, you can reuse the same Javabean class in all other layers of your application. E.g. to store data in a DB, or to transfer the data between layers, or to present the data to the enduser, etc.

And surely such a class can have constructors and methods.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • POJO is a GREAT name, but it does not mean Java Bean, it means a class that has no requirements. In fact, you could claim that a Java Bean is not a POJO because it requires setters, getters and serialization. – Bill K Feb 22 '12 at 01:01