Java Code Examples for com.google.gson.JsonArray.toString()

The following are Jave code examples for showing how to use toString() of the com.google.gson.JsonArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gremzeppelin   File: GremlinInterpreter.java   Source Code and License Vote up 7 votes
@Override
public InterpreterResult interpret(String gremlin, InterpreterContext interpreterContext) {
    logger.info("execute gremlin traversal {}", gremlin);
    try {
        ResultSet results = client.submit(gremlin);
        JsonArray array = results.stream()
                                 .map(result -> new JsonPrimitive(results.toString()))
                                 .collect(JsonArray::new, JsonArray::add, JsonArray::addAll);

        //TODO extract ResultSet
        //Case MessageSerializer

        return new InterpreterResult(InterpreterResult.Code.SUCCESS, array.toString());
    } catch (RuntimeException e) {
        return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage());
    }
}
 
Example 2
Project: digital-display-garden-iteration-3-sixguysburgers-fries   File: PlantController.java   Source Code and License Vote up 6 votes
public String makeJSON(Object[][] in) {
    JsonArray outerArray = new JsonArray();
    for (int i = 0; i < in.length; i++) {
        JsonArray innerArray = new JsonArray();
        for (int j = 0; j < in[i].length; j++) {
            Object a = in[i][j];
            Class objectClass = a.getClass();
            if (objectClass == String.class) {
                innerArray.add(in[i][j].toString());
            } else if (Number.class.isAssignableFrom(objectClass)) {
                innerArray.add((Number) in[i][j]);
            } else if (objectClass == JsonElement.class) {
                innerArray.add((JsonElement) in[i][j]);
            } else {
                throw new RuntimeException("WHAT ARE YOU");
            }
        }

        outerArray.add(innerArray);
    }
    return outerArray.toString();
}
 
Example 3
Project: moebooru-android   File: GetPost.java   Source Code and License Vote up 5 votes
private List<RawPostBean> getRawPostBean(String data){
        if (data == null){
            Log.i(TAG,"string 为空");
            return null;
        }
        JsonParser jsonParser = new JsonParser();
        JsonArray jsonArray = jsonParser.parse(data).getAsJsonArray();
        String string = jsonArray.toString();
        if (!jsonArray.isJsonNull()){
            //保存 json 供下次打开时读取缓存中的图片
            //只在刷新时保存
            if (this.mPage == 1 && mType.equals("post")){
                Log.i(TAG, mType);
                new FileUtils().saveJson(string);
            }
            Log.i(TAG, mType);
            //转换为 List<RawPostBean>
            for (JsonElement post : jsonArray){
                RawPostBean rawPostBean = mGson.fromJson(post, RawPostBean.class);
                mRawPostBeanList.add(rawPostBean);
            }

//        Log.i("TAGS", String.valueOf(postBeanList.get(0).getTags().size()));
            return mRawPostBeanList;
        }
        Log.i("getPostBean","结果为空");
        return null;
    }
 
Example 4
Project: digital-display-garden-iteration-4-revolverenguardia-1   File: GardenCharts.java   Source Code and License Vote up 5 votes
/**
 * Creates a two dimensional Json array from an Object[][] in.
 *
 * Valid Objects to put in the Object[][] are Strings, Numbers (bool, integer, double, etc.), and JsonElements
 *
 * @param in
 * @return
 */
public String makeJSON(Object[][] in) {

    JsonArray outerArray = new JsonArray();
    for(int i = 0; i < in.length; i++) {
        JsonArray innerArray = new JsonArray();
        for(int j = 0; j < in[i].length; j++) {
            Object a = in[i][j];
            Class objectClass = a.getClass();
            if(objectClass == String.class)
            {
                innerArray.add(in[i][j].toString());
            }
            else if(Number.class.isAssignableFrom(objectClass))
            {
                innerArray.add((Number)in[i][j]);
            }
            else if(objectClass == JsonElement.class)
            {
                innerArray.add((JsonElement)in[i][j]);
            }
            else
            {
                throw new RuntimeException("WHAT ARE YOU");
            }
        }

        outerArray.add(innerArray);
    }
    return outerArray.toString();
}
 
Example 5
Project: cyberduck   File: SwiftSegmentService.java   Source Code and License Vote up 5 votes
/**
 * Create the appropriate manifest structure for a static large object (SLO).
 * The number of object segments is limited to a configurable amount, default 1000. Each segment,
 * except for the final one, must be at least 1 megabyte (configurable).
 *
 * @param objects Ordered list of segments
 * @return ETag returned by the simple upload total size of segment uploaded path of segment
 */
public String manifest(final String container, final List<StorageObject> objects) {
    JsonArray manifestSLO = new JsonArray();
    for(StorageObject s : objects) {
        JsonObject segmentJSON = new JsonObject();
        // this is the container and object name in the format {container-name}/{object-name}
        segmentJSON.addProperty("path", String.format("/%s/%s", container, s.getName()));
        // MD5 checksum of the content of the segment object
        segmentJSON.addProperty("etag", s.getMd5sum());
        segmentJSON.addProperty("size_bytes", s.getSize());
        manifestSLO.add(segmentJSON);
    }
    return manifestSLO.toString();
}
 
Example 6
Project: mongodb-rdbms-sync   File: DatabaseDetailsController.java   Source Code and License Vote up 5 votes
@RequestMapping(value = "/fetchColumnsForMultipleTables")
public void fetchColumnsForMultipleTables(HttpServletRequest request, HttpServletResponse response) throws IOException {
	logger.info("Inside fetchColumnsForMultipleTables");
	String jsonColumnsDtl = "";
	List<String> tableNameList = null;
	JsonArray jsonArray = new JsonArray();
	Gson gson = new Gson();
	String tableName = request.getParameter("tableName").trim().equalsIgnoreCase("") ? ""
			: request.getParameter("tableName").trim();
	logger.info("Fetch column for TableName : " + tableName);
	String sourceDatabaseName = request.getParameter("sourceDatabaseName");
	logger.info("Source DB is:" + sourceDatabaseName);
	String sourceDatabaseSchema = request.getParameter("sourceDatabaseSchema");
	logger.info("Source schema is:" + sourceDatabaseSchema);
	if(tableName != null && !tableName.isEmpty()){
		tableNameList = Arrays.asList(tableName.split(","));
	}
	DatabaseDetailsService databaseDetailsService = new DatabaseDetailsServiceImpl();
	Map<String, Object> outPut = databaseDetailsService.fetchColumnsForMultipleTables(sourceDatabaseName,sourceDatabaseSchema, tableNameList);
	if (SyncConstants.SUCCESS.equalsIgnoreCase(String.valueOf(outPut.get("result")))) {
		@SuppressWarnings("unchecked")
		Map<String, OracleColumn> columnsMap = (Map<String, OracleColumn>) outPut.get("output");
		for(Entry<String,OracleColumn> entry : columnsMap.entrySet()){
			JsonObject obj = new JsonObject();
			obj.addProperty("tableName", entry.getKey());
			JsonElement jsonElement = gson.toJsonTree(entry.getValue());
			obj.add("columns", jsonElement);
			jsonArray.add(obj);
		}
	}
	jsonColumnsDtl = jsonArray.toString();
	response.setContentType(SyncConstants.CONTENT_TYPE_JSON);
	response.getWriter().println(jsonColumnsDtl);
	logger.info("Inside fetchColumnsForMultipleTables Completed");
}
 
Example 7
Project: digital-display-garden-iteration-4-revolverenguardia-1   File: GardenCharts.java   Source Code and License Vote up 4 votes
/**
 * Form a JSON to pass to the client to render in the Google Maps Bed Metadata Map
 *
 * This returns an array with an entry for each gardenLocation
 * {gardenLocation : string, likes : number, dislikes : number, comments : number}
 * @param plantController
 * @param uploadID
 * @return
 */
public String getBedMetadataForMap(PlantController plantController, String uploadID) {
    // Count Flower likes
    // Count flower dislikes
    // Count flower comments

    try {


        String[] bedNames = plantController.getGardenLocations(uploadID);
        JsonArray out = new JsonArray();

        for (int i = 0; i < bedNames.length; i++) {
            int likes = 0;
            int dislikes = 0;
            int comments = 0;
            JsonObject bed = new JsonObject();
            Document filter = new Document();
            filter.append("uploadId", uploadID);
            filter.append("gardenLocation", bedNames[i]);

            FindIterable<Document> iter = plantCollection.find(filter);
            for (Document plant : iter) {
                long[] feedback = plantController.getPlantFeedbackByPlantId(plant.getString("id"), uploadID);

                likes += feedback[PlantController.PLANT_FEEDBACK_LIKES];
                dislikes += feedback[PlantController.PLANT_FEEDBACK_DISLIKES];
                comments += feedback[PlantController.PLANT_FEEDBACK_COMMENTS];
            }
            bed.addProperty("gardenLocation", bedNames[i]);
            bed.addProperty("likes", likes);
            bed.addProperty("dislikes", dislikes);
            bed.addProperty("comments", comments);//TODO: could be refactored to include pageViews
            out.add(bed);
        }

        return out.toString();
    }
    catch(Exception e)
    {
        e.printStackTrace();
        throw e;
    }
}
 
Example 8
Project: digital-display-garden-iteration-4-revolverenguardia-1   File: GardenCharts.java   Source Code and License Vote up 4 votes
/**
 * Form a JSON to pass to the client to render in the BubbleMap google chart.
 *
 * This returns an array with an entry for each gardenLocation
 * {gardenLocation : string, likes : number, pageViews : number}
 * @param plantController in order to getGardenLocations and PlantFeedback to count likes
 * @param bedController in order to get Page views for a bed
 * @param uploadID
 * @return
 */
public String getBedMetadataForBubbleMap(PlantController plantController, BedController bedController, String uploadID) {
    // Count Flower likes
    // Count flower dislikes
    // Count flower comments

    try {
        int pageViews;

        String[] bedNames = plantController.getGardenLocations(uploadID);
        JsonArray out = new JsonArray();

        for (int i = 0; i < bedNames.length; i++) {
            int likes = 0;
            JsonObject bed = new JsonObject();
            Document filter = new Document();
            filter.append("uploadId", uploadID);
            filter.append("gardenLocation", bedNames[i]);

            FindIterable<Document> iter = plantCollection.find(filter);
            for (Document plant : iter) {
                long[] feedback = plantController.getPlantFeedbackByPlantId(plant.getString("id"), uploadID);
                likes += feedback[PlantController.PLANT_FEEDBACK_LIKES];
            }

            pageViews = bedController.getPageViews(bedNames[i], uploadID);

            bed.addProperty("gardenLocation", bedNames[i]);
            bed.addProperty("likes", likes);
            bed.addProperty("pageViews", pageViews);
            out.add(bed);
        }

        return out.toString();
    }
    catch(Exception e)
    {
        e.printStackTrace();
        throw e;
    }
}