0

I want to make a CRUD website using a package from a web service. How can I get JSON format for return response? This code is to select a member using member id

try {
        WsOtherLocator locator = new WsOtherLocator();
        WsOtherSoap soapws = locator.getWsOtherSoap();
        Browse_1_1ResponseBrowse_1_1Result result = soapws.browse_1("0040041100002","admin", "admin", "admin", "PKG_ADMIN.BRW_ADMIN_ID");
        System.out.print(result);

    }
    catch (Exception ex){
        ex.printStackTrace();
    }

Those are the coding for calling browse_1 method in wsdl file, with one parameter which is member id, calling package pgk_admin and package method brw_admin_id. But after I ran it I got

org.tempuri.wynaws.wsother.Browse_1_1ResponseBrowse_1_1Result@41dd0e27

as a result of my code, I want it to be in JSON format, how I can change it?

Unheilig
  • 16,196
  • 193
  • 68
  • 98
ezra putra
  • 1
  • 1
  • 5

1 Answers1

0

you are getting that output because the class Browse_1_1ResponseBrowse_1_1Result does not implement toString() method.

The easiest way to serialize it in json is using Gson:

Gson gson = new Gson();
System.out.println(gson.toJson(result)

Ref: https://sites.google.com/site/gson/gson-user-guide

Chocksmith
  • 1,188
  • 2
  • 12
  • 40
  • the output should be xml, but i couldnt get any xml file, can you correct my code? – ezra putra Apr 20 '20 at 02:52
  • you asked for JSON you got it. If it works, accept the answer. If you need XML now, you may try using http://www.jdom.org. Do your homework before asking how to do it. There are plenty of articles on the topic. – Chocksmith Apr 20 '20 at 11:18