Example usage for com.google.gson JsonObject toString

List of usage examples for com.google.gson JsonObject toString

Introduction

In this page you can find the example usage for com.google.gson JsonObject toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this element.

Usage

From source file:com.adssets.servlet.ObjectServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from  w  w  w . j  av a2  s. c  o m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setHeader("Access-Control-Allow-Origin", "*");
    try (PrintWriter out = response.getWriter()) {
        StringBuilder sb = new StringBuilder();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null)
                sb.append(line);
        } catch (Exception e) {
            System.out.println(
                    "com.adssets.servlet.ObjectServlet.processRequestPost()" + " Could not read POST body");
        }

        JsonObject jsonObject = (new JsonParser()).parse(sb.toString()).getAsJsonObject();

        if (jsonObject.has("marketId") && jsonObject.has("json")) {
            System.out.println(jsonObject.toString());
            String res = data.createFeed(jsonObject.toString());
            out.println(res);
        } else {
            System.out.println(
                    "com.adssets.servlet.ObjectServlet.processRequestPost()" + " Missing fields in body");

        }

    }
}

From source file:com.aliyun.odps.udf.utils.CounterUtils.java

License:Apache License

/**
 *  {@link Counters} ?JSON/*w  w  w  . java 2s  .c o  m*/
 *
 * @param counters
 *     ? {@link Counters} 
 * @return JSON
 */
public static String toJsonString(Counters counters) {
    JsonObject js = toJson(counters);
    return js.toString();
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public long registerUser(String nickname) throws IOException {
    boolean ok;/*from www  . j  av  a 2 s  . com*/
    String res;

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    jsonParam.addProperty("devicename", "devicename");
    jsonParam.addProperty("pushtoken", "pushtoken");
    res = sendJsonPostRequest(REGISTER_USER, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to register");
    }
    return Long.parseLong(res);
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean unregisterUser(String nickname) throws IOException {
    String res;/*from  ww w.jav a 2 s .  c om*/

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    res = sendJsonPostRequest(UNREGISTER_USER, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to register");
    }

    return true;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean postComment(String nickname, String comment) throws IOException {
    String res;/* w  w  w .ja  va 2s .c o m*/

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    jsonParam.addProperty("comment", comment);
    res = sendJsonPostRequest(POST_COMMENT, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to post comment");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean waitAtStop(String stopId, String nickname) throws IOException {
    String res;/*from   w  ww.  ja v  a 2  s . com*/

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    jsonParam.addProperty("stopId", stopId);
    jsonParam.addProperty("agencyKey", agencyKey);
    res = sendJsonPostRequest(WAIT_AT_STOP, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to wait at stop");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean leaveStop(String nickname) throws IOException {
    String res;/* ww  w  .j ava 2  s.c o m*/

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    res = sendJsonPostRequest(LEAVE_STOP, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to leave stop");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean enterShuttle(String nickname, String shuttleId) throws IOException {
    String res;//w ww . j  a v a  2s .  com

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    jsonParam.addProperty("shuttleId", shuttleId);
    jsonParam.addProperty("agencyKey", agencyKey);
    res = sendJsonPostRequest(ENTER_SHUTTLE, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to leave stop");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean leaveShuttle(String nickname) throws IOException {
    String res;/* w ww.j av a  2 s  .  c  o m*/

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    res = sendJsonPostRequest(LEAVE_SHUTTLE, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to leave stop");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}

From source file:com.ambientic.shuttler.ShuttlerServiceImpl.java

License:Open Source License

@Override
public boolean updatePosition(String nickname, PositionInfo position) throws IOException {
    String res;//  w ww  . j  av  a  2  s . c o  m

    JsonObject jsonParam = new JsonObject();
    jsonParam.addProperty("nickname", nickname);
    jsonParam.addProperty("position", gson.toJson(position));
    res = sendJsonPostRequest(UPDATE_POSITION, jsonParam.toString());

    if (res == null) {
        throw new IOException("Unable to leave stop");
    }

    if (res.equals("true"))
        return true;
    else
        return false;
}