Package com.github.jsonj

Examples of com.github.jsonj.JsonElement


     * @param lineString 2d JsonArray
     * @return 3d double array with the polygon
     */
    public static JsonArray lineStringToPolygon(JsonArray lineString) {
        if(!lineString.first().equals(lineString.last())) {
            JsonElement e = lineString.first().deepClone();
            lineString.add(e);
        }
        return array(lineString);
    }
View Full Code Here


            }
        } else {
            if(array.size() < 2) {
                throw new IllegalArgumentException("need at least two coordinates");
            }
            JsonElement first = array.get(0);
            JsonElement second = array.get(1);
            array.set(0, second);
            array.set(1, first);

        }
        return array;
View Full Code Here

            try {
                child = new Element(entry.getKey());
            } catch (IllegalNameException exc1) {
                child = new Element("_" + entry.getKey());
            }
            JsonElement value = entry.getValue();
            if(value.isArray()) {
                append(child, value.asArray());
            } else if(value.isObject()) {
                append(child, value.asObject());
            } else {
                append(child, value.asPrimitive());
            }

            e.appendChild(child);
        }
    }
View Full Code Here

            newline(bw, indent+1, pretty);
            Iterator<Entry<String, JsonElement>> iterator = json.asObject().entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, JsonElement> entry = iterator.next();
                String key = entry.getKey();
                JsonElement value = entry.getValue();
                if(value != null) {
                    bw.write('"');
                    bw.write(jsonEscape(key));
                    bw.write("\":");
                    serialize(bw,value,pretty,indent+1);
                    if(iterator.hasNext()) {
                        bw.write(',');
                        newline(bw, indent+1, pretty);
                    }
                }
            }
            newline(bw, indent, pretty);
            bw.write('}');
            break;
        case array:
            bw.write('[');
            newline(bw, indent+1, pretty);
            Iterator<JsonElement> arrayIterator = json.asArray().iterator();
            while (arrayIterator.hasNext()) {
                JsonElement value = arrayIterator.next();
                boolean nestedPretty=false;
                if(value.isObject()) {
                    nestedPretty=true;
                }
                serialize(bw,value,nestedPretty,indent+1);
                if(arrayIterator.hasNext()) {
                    bw.write(',');
View Full Code Here

        JsonPrimitive primitive;
        primitive = new JsonPrimitive(object);
        if (isObject) {
            stack.add(primitive);
        } else {
            JsonElement peekLast = stack.peekLast();
            if (peekLast instanceof JsonArray) {
                peekLast.asArray().add(primitive);
            } else {
                stack.add(primitive);
            }
        }
        return true;
View Full Code Here

        }
        return true;
    }

    public boolean endObjectEntry() {
        JsonElement value = stack.pollLast();
        JsonElement e = stack.peekLast();
        if (e.isPrimitive()) {
            e = stack.pollLast();
            JsonElement last = stack.peekLast();
            if (last.isObject()) {
                JsonObject container = last.asObject();
                String key = e.asPrimitive().asString();
                container.put(key, value);
            } else if (last.isArray()) {
                throw new IllegalStateException("shouldn't happen");

            }
        }
        return true;
View Full Code Here

        return true;
    }

    public boolean endObject() {
        if (stack.size() > 1 && stack.get(stack.size() - 2).isArray()) {
            JsonElement object = stack.pollLast();
            stack.peekLast().asArray().add(object);
        }
        return true;
    }
View Full Code Here

    public void endJSON() {
    }

    public boolean endArray() {
        if (stack.size() > 1 && stack.get(stack.size() - 2).isArray()) {
            JsonElement value = stack.pollLast();
            stack.peekLast().asArray().add(value);
        }
        return true;
    }
View Full Code Here

    }

    @Test(dataProvider="goodJson")
    public void shouldParse(final JsonElement element) {
        String input = JsonSerializer.serialize(element, false);
        JsonElement parsed = jsonParser.parse(input);
        Assert.assertEquals(JsonSerializer.serialize(parsed, false), input);
        // check with the other parser as well
    }
View Full Code Here

        for(int i = 0; i<100000; i++) {
            tasks.add(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    JsonElement output;
                    output = jsonParser.parse(input);
                    String serialized = JsonSerializer.serialize(output, false);
                    return input.equals(serialized);
                }
            });
View Full Code Here

TOP

Related Classes of com.github.jsonj.JsonElement

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.