Package com.couchbase.client.java.document.json

Examples of com.couchbase.client.java.document.json.JsonArray


                    try {
                        converted = CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER.stringToJsonObject(response.content());
                    } catch (Exception e) {
                        throw new TranscodingException("Could not decode design document.", e);
                    }
                    JsonArray rows = converted.getArray("rows");
                    List<DesignDocument> docs = new ArrayList<DesignDocument>();
                    for (Object doc : rows) {
                        JsonObject docObj = ((JsonObject) doc).getObject("doc");
                        String id = docObj.getObject("meta").getString("id");
                        String[] idSplit = id.split("/");
View Full Code Here


                }
            }).flatMap(new Func1<BucketsConfigResponse, Observable<BucketSettings>>() {
                @Override
                public Observable<BucketSettings> call(BucketsConfigResponse response) {
                    try {
                        JsonArray decoded = CouchbaseAsyncBucket.JSON_ARRAY_TRANSCODER.stringToJsonArray(response.config());
                        List<BucketSettings> settings = new ArrayList<BucketSettings>();
                        for (Object item : decoded) {
                            JsonObject bucket = (JsonObject) item;
                            settings.add(DefaultBucketSettings.builder()
                                .name(bucket.getString("name"))
View Full Code Here

        if (!TranscoderUtils.hasJsonFlags(flags)) {
            throw new TranscodingException("Flags (0x" + Integer.toHexString(flags) + ") indicate non-JSON array document for "
                + "id " + id + ", could not decode.");
        }

        JsonArray converted = stringToJsonArray(content.toString(CharsetUtil.UTF_8));
        content.release();
        return newDocument(id, expiry, converted, cas);
    }
View Full Code Here

        if (!TranscoderUtils.hasJsonFlags(flags)) {
            throw new TranscodingException("Flags (0x" + Integer.toHexString(flags) + ") indicate non-JSON array document for "
                + "id " + id + ", could not decode.");
        }

        JsonArray converted = stringToJsonArray(content.toString(CharsetUtil.UTF_8));
        return newDocument(id, expiry, converted, cas);
    }
View Full Code Here

                }
            }).flatMap(new Func1<BucketsConfigResponse, Observable<BucketSettings>>() {
                @Override
                public Observable<BucketSettings> call(BucketsConfigResponse response) {
                    try {
                        JsonArray decoded = CouchbaseAsyncBucket.JSON_ARRAY_TRANSCODER.stringToJsonArray(response.config());
                        List<BucketSettings> settings = new ArrayList<BucketSettings>();
                        for (Object item : decoded) {
                            JsonObject bucket = (JsonObject) item;

                            int ramQuota = 0;
View Full Code Here

        converter = new JsonArrayTranscoder();
    }

    @Test
    public void shouldEncodeEmptyJsonArray() {
        JsonArray array = JsonArray.empty();

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonArrayDocument.create("id", array));
        assertEquals("[]", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

        converter.decode("id", content, 0, 0, wrongFlags, ResponseStatus.SUCCESS);
    }

    @Test
    public void shouldEncodeArrayWithEmptyObject() {
        JsonArray array = JsonArray.create();
        array.add(JsonObject.create());

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonArrayDocument.create("id", array));
        assertEquals("[{}]", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

        assertTrue(decoded.content().getObject(0).isEmpty());
    }

    @Test
    public void shouldEncodeMixedJsonValues() throws Exception {
        JsonArray object = JsonArray.create();
        object.add("Hello World");
        object.add(1);
        object.add(Long.MAX_VALUE);
        object.add(11.3322);
        object.add(true);

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonArrayDocument.create("id", object));
        List<Object> control = readJsonIntoList(encoded.value1());

        assertEquals(5, control.size());
View Full Code Here

    public void shouldDecodeMixedJsonValues() throws Exception {
        ByteBuf content = Unpooled.copiedBuffer("[\"Hello World\",1,9223372036854775807,11.3322,true]",
            CharsetUtil.UTF_8);
        JsonArrayDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS,
            ResponseStatus.SUCCESS);
        JsonArray found = decoded.content();

        assertFalse(found.isEmpty());
        assertEquals(5, found.size());
        assertEquals(true, found.getBoolean(4));
        assertEquals(1, (int) found.getInt(1));
        assertEquals("Hello World", found.getString(0));
        assertEquals(11.3322, found.getDouble(3), 0);
        assertEquals(Long.MAX_VALUE, (long) found.getLong(2));
    }
View Full Code Here

TOP

Related Classes of com.couchbase.client.java.document.json.JsonArray

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.