1

I have a Java code which is writing some data in string format to Messaging queue. Now any one can subscribe to this queue and fetch this data. Here the client fetching this data can be written in any programming language.

I was planning to expose this data in JSON format, but then as per my understanding I have to expose my Bean Object, as the Object is needed to parse this JSON string. And in this case I am limiting client to be Java only.

I don't want to have any of such a limitations, so now I am looking to expose this data as XML.

Any other way so that I can still use JSON here?

4
  • 4
    I think you assumption that "Bean Object is needed to parse JSON string" is essentially wrong. You give to little details to judge, but JSON is very wide-spread and there are libraries for other languages to parse it.
    – superM
    Commented Aug 30, 2013 at 7:14
  • 1
  • 2
    I don't see this as a duplicate of that question - JSON or XML are not even mentioned in any of the answers.
    – Doc Brown
    Commented Aug 30, 2013 at 9:54
  • Gazillions of iOS applications parse JSON quite happily without any bean in sight. And parsing JSON is considerably easier than parsing XML.
    – gnasher729
    Commented Jun 24, 2015 at 13:07

2 Answers 2

2

You can't do something that contains anything and is readable for everyone. That is why you need data transfer objects on both sides. You can deserialize JSON sent by Java in C# for instance, but C# client has to know what he is trying to deserialize.

Of course it is not really strict so you can send some fields of object in JSON and deserialization will set not present fields to default values.

Some languages have possibility to use anonymous objects so it would be possible, but later on you will have to know what you want to do with it.

Long story short, either way client has to know what he gets, but you can write documentation about sent fields, serialized to JSON Java class documentation would be enough for other developer to receive stuff and translate it to his language.

1

http://www.json.org/ shows a list of JSON libs and resources for more than 50 programming languages. You have to decide if that is enough support for your case. Nevertheless, there are indeed situations where XML (still) is better suited. For example, MS Excel has native XML support, but no native JSON support (though one can come around this restriction, see here, for example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.