1

I understand that java objects can be serialized to a file, but under what circumstances would we need to use an XMLEncoder and serialize an object as XML?

I'm starting to get a grip with Java EE and I understand that we can serialize beans using this method, but why exactly do we need to do it like this and for what purpose?

Coder
  • 101
  • 1
  • 1
  • 8
  • 1
    Downstream applications may not use Java, or your upstream application may be proprietary. – Compass Jun 27 '16 at 17:35
  • 1
    Why send in XML, or JSON, or some other format? Because that is what the code at the other end expects/understands. As long as both sides agree on format, you can send in any format you want, e.g. you could encode it in morse code, if you were so inclined. – Andreas Jun 27 '16 at 17:46

1 Answers1

3

You'd do this if you were going to pass something to an endpoint (e.g. REST) that accepts XML that may be part of your app. XML isn't currently as popular as something like JSON but there are still many APIs out there that use it, including something you may end up working on.

Darwin Allen
  • 190
  • 4
  • 15