Example usage for io.vertx.core.json JsonObject JsonObject

List of usage examples for io.vertx.core.json JsonObject JsonObject

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject JsonObject.

Prototype

public JsonObject() 

Source Link

Document

Create a new, empty instance

Usage

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example13_0(MongoClient mongoService) {
    JsonObject document = new JsonObject().put("title", "The Hobbit")
            //ISO-8601 date
            .put("publicationDate", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
    mongoService.save("publishedBooks", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            mongoService.findOne("publishedBooks", new JsonObject().put("_id", id), null, res2 -> {
                if (res2.succeeded()) {
                    System.out.println("To retrieve ISO-8601 date : "
                            + res2.result().getJsonObject("publicationDate").getString("$date"));
                } else {
                    res2.cause().printStackTrace();
                }/*  w  ww. jav a  2s .  c o  m*/
            });
        } else {
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

@Source(translate = false)
public void example14_01_dl(MongoClient mongoService) {
    //This could be a serialized object or the contents of a pdf file, etc,  in real life
    byte[] binaryObject = new byte[40];
    JsonObject document = new JsonObject().put("name", "Alan Turing").put("binaryStuff",
            new JsonObject().put("$binary", binaryObject));
    mongoService.save("smartPeople", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            mongoService.findOne("smartPeople", new JsonObject().put("_id", id), null, res2 -> {
                if (res2.succeeded()) {
                    byte[] reconstitutedBinaryObject = res2.result().getJsonObject("binaryStuff")
                            .getBinary("$binary");
                    //This could now be de-serialized into an object in real life
                } else {
                    res2.cause().printStackTrace();
                }//from   w  w  w.  j  ava  2  s  . c  o m
            });
        } else {
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example14_02_dl(MongoClient mongoService) {
    //This could be a the byte contents of a pdf file, etc converted to base 64
    String base64EncodedString = "a2FpbHVhIGlzIHRoZSAjMSBiZWFjaCBpbiB0aGUgd29ybGQ=";
    JsonObject document = new JsonObject().put("name", "Alan Turing").put("binaryStuff",
            new JsonObject().put("$binary", base64EncodedString));
    mongoService.save("smartPeople", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            mongoService.findOne("smartPeople", new JsonObject().put("_id", id), null, res2 -> {
                if (res2.succeeded()) {
                    String reconstitutedBase64EncodedString = res2.result().getJsonObject("binaryStuff")
                            .getString("$binary");
                    //This could now converted back to bytes from the base 64 string
                } else {
                    res2.cause().printStackTrace();
                }/*from   ww w.  j av  a2s  .  c o  m*/
            });
        } else {
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example15_dl(MongoClient mongoService) {
    String individualId = new ObjectId().toHexString();
    JsonObject document = new JsonObject().put("name", "Stephen Hawking").put("individualId",
            new JsonObject().put("$oid", individualId));
    mongoService.save("smartPeople", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            JsonObject query = new JsonObject().put("_id", id);
            mongoService.findOne("smartPeople", query, null, res2 -> {
                if (res2.succeeded()) {
                    String reconstitutedIndividualId = res2.result().getJsonObject("individualId")
                            .getString("$oid");
                } else {
                    res2.cause().printStackTrace();
                }//  w  w w  . ja v  a  2  s  .c  o  m
            });
        } else {
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example16(MongoClient mongoClient) {
    JsonObject document = new JsonObject().put("title", "The Hobbit");
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            mongoClient.distinct("books", "title", String.class.getName(), res2 -> {
                System.out.println("Title is : " + res2.result().getJsonArray(0));
            });/*from ww  w. j  a  v  a 2  s.  c  om*/
        } else {
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example16_d1(MongoClient mongoClient) {
    JsonObject document = new JsonObject().put("title", "The Hobbit");
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            mongoClient.distinctBatch("books", "title", String.class.getName())
                    .handler(book -> System.out.println("Title is : " + book.getString("title")));
        } else {//from   w ww .  j  a  v a 2  s . c  o  m
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example17(MongoClient mongoClient) {
    JsonObject document = new JsonObject().put("title", "The Hobbit").put("publicationDate",
            new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
    JsonObject query = new JsonObject().put("publicationDate",
            new JsonObject().put("$gte", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00")));
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            mongoClient.distinctWithQuery("books", "title", String.class.getName(), query, res2 -> {
                System.out.println("Title is : " + res2.result().getJsonArray(0));
            });/*  w  w  w .  jav  a 2s.  c  om*/
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example17_d1(MongoClient mongoClient) {
    JsonObject document = new JsonObject().put("title", "The Hobbit").put("publicationDate",
            new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
    JsonObject query = new JsonObject().put("publicationDate",
            new JsonObject().put("$gte", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00")));
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            mongoClient.distinctBatchWithQuery("books", "title", String.class.getName(), query)
                    .handler(book -> System.out.println("Title is : " + book.getString("title")));
        }//w ww.j ava 2s.  c om
    });
}

From source file:examples.MySQLClientExamples.java

public void jsonExample() {

    // Create a tuple
    Tuple tuple = Tuple.of(Tuple.JSON_NULL, new JsonObject().put("foo", "bar"), 3);

    // Retrieving json
    Object value = tuple.getValue(0); // Expect JSON_NULL

    ///*from   w  ww  .j  av  a  2  s. c  o m*/
    value = tuple.get(JsonObject.class, 1); // Expect JSON object

    //
    value = tuple.get(Integer.class, 2); // Expect 3
    value = tuple.getInteger(2); // Expect 3
}

From source file:examples.RedisDataSourceExamples.java

License:Open Source License

public void example1(ServiceDiscovery discovery) {
    Record record = RedisDataSource.createRecord("some-redis-data-source-service", // The service name
            new JsonObject().put("url", "localhost"), // The location
            new JsonObject().put("some-metadata", "some-value") // Some metadata
    );//w ww .  j ava  2  s .  c  o  m

    discovery.publish(record, ar -> {
        // ...
    });
}