0

I am trying to send json request using marshalling logic to server? How to get json as response from server ? Do i have to parse it using below parser?

final SAXParserFactory sp = SAXParserFactory.newInstance();
final SAXParser sp1 = sp.newSAXParser();
User2413
  • 605
  • 6
  • 22
  • 51
  • SAXParser is for XML not for JSON. What do you really want to parse? Maybe the answer in https://stackoverflow.com/questions/23479332/import-json-url-to-java-and-parse-it-using-jackson-library will help. – SirFartALot Apr 05 '19 at 05:42
  • @SirFartALot I want to get Json as response from server...That is my requirement – User2413 Apr 05 '19 at 05:47
  • Possible duplicate of [Parsing JSON from URL](https://stackoverflow.com/questions/7467568/parsing-json-from-url) – SirFartALot Apr 05 '19 at 05:49
  • It depends from the libraries do you use. For example [`Spring` `RestTemplate`](https://www.baeldung.com/rest-template) call differs from [`Feign`](https://www.baeldung.com/intro-to-feign). See also: [How to use OpenFeign to get a pojo array?](https://stackoverflow.com/questions/55012543/how-to-use-openfeign-to-get-a-pojo-array), [Get list of JSON objects with Spring RestTemplate](https://stackoverflow.com/questions/23674046/get-list-of-json-objects-with-spring-resttemplate). – Michał Ziober Apr 05 '19 at 08:54

1 Answers1

1

The data format of the results depend on what your server response to you . you can translate the result string responsed by the server to pojo no mater the data format is xml or json .

If data format is xml , you can use JAXB to translate it to pojo

If data format is json ,you can use Gson to translate it to pojo

If you want to directly translte xml to json . Maybe gson-xml library can help you.

Cyrus
  • 8,995
  • 9
  • 31
  • 58