Package net.minidev.json

Examples of net.minidev.json.JSONObject


        return ob.hashCode();
    }

    protected int testJsonOrgViaJackson(int reps) throws Exception
    {
        JSONObject ob = null;
        for (int i = 0; i < reps; ++i) {
            ob = _mapper.readValue(_jsonData, JSONObject.class);
        }
        return ob.hashCode();
    }
View Full Code Here


    }
   
    private int testJsonSmart(int reps, byte[] dataBytes, String dataString)
        throws Exception
    {
        JSONObject root = null;
        final Charset utf8 = Charset.forName("UTF-8");
        for (int i = 0; i < reps; ++i) {
    //        ob = mapper.readValue(data, JsonNode.class);
            String str = new String(dataBytes, utf8);
            root = (JSONObject) JSONValue.parse(str);
        }
        return root.hashCode();
    }
View Full Code Here

    langs.add(LangTag.parse("en-US"));
    langs.add(LangTag.parse("en-GB"));
    langs.add(LangTag.parse("de-DE"));
    langs.add(LangTag.parse("fr-FR"));
   
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("languages", langs);
   
    jsonObject.put("defaultLanguage", LangTag.parse("en-US"));
   
    System.out.println(jsonObject);
  }
View Full Code Here

    public JSONObject buildFrom(Resource<ServerStats> resource) {
       
        ServerStats serverStats = resource.getDefault();

        JSONObject statsJson = new JSONObject();

        statsJson.put("numberOfGamesPlayed", serverStats.getNumberOfGamesPlayed());
        statsJson.put("numberOfUniquePlayers", serverStats.getNumberOfUniquePlayers());
        statsJson.put("numberOfPlayersPlayedOnlyOnce", serverStats.getNumberOfPlayersPlayedOnce());
        statsJson.put("top3Players", serverStats.getTop3Players());

        return statsJson;
    }
View Full Code Here

     * @param resource Resource to build response based on
     * @return
     */
    public final Response responseWithError(Resource resource) {
        long t1 = System.currentTimeMillis();
        JSONObject response = buildResponse(resource);
        response = verifyResponse(response);
        String json = prettifyResponse(response);

        Response responseObject = Response.status(200).entity(json).build();
        long t2 = System.currentTimeMillis();
View Full Code Here

import net.minidev.json.JSONObject;

public class ResponseBuilder {

    public static JSONObject build(int code) {
        JSONObject response = new JSONObject();
        response.put("code", code);

        return response;
    }
View Full Code Here

        logger.info("responseWithError time: " + (t2 - t1) + "ms");
        return responseObject;
    }

    private JSONObject buildResponse(Resource resource) {
        JSONObject response = null;
        try {
            response = ResponseBuilder.build(resource);
        } catch (Exception e) {
            logger.error("responseWithError: ", e);
View Full Code Here

        return response;
    }

    public static JSONObject build(int code, String name, JSONObject jsonObject) {
        JSONObject response = new JSONObject();
        response.put("code", code);
        response.put(name, jsonObject);

        return response;
    }
View Full Code Here

        return response;
    }

    public static JSONObject build(Resource resource) {
        if (resource.getError() != DomainErrors.Errors.STATUS_OK.getCode()) {
            JSONObject response = ResponseBuilder.build(resource.getError());
            response.put("message", resource.getErrorMessage());
            return response;
        } else {
            JSONObject json = resource.getJSONBody();
            return ResponseBuilder.build(DomainErrors.Errors.STATUS_OK.getCode(), resource.getName(), json);
        }

    }
View Full Code Here

        } catch (Exception e) {
            logger.error("Error: ", e);
        }

        Resource resource = new ErrorResource(DomainErrors.Errors.STATUS_SERVER_ERROR, "server_error");
        JSONObject serverError = ResponseBuilder.build(resource);

        return Response.status(200).entity(serverError.toJSONString()).build();
  }
View Full Code Here

TOP

Related Classes of net.minidev.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.