List of usage examples for io.vertx.core.json JsonObject put
public JsonObject put(String key, Object value)
From source file:com.nasa.Transformer.java
public static JsonObject conditionToMap(JsonObject jsonObject) { // private String conditionsMap = "{\n" // + " \"Diseases\": [\n" // + " {\n" // + " \"lat\": 46.77029284,\n" // + " \"lng\": 23.57641889,\n" // + " \"type\": \"something good\",\n" // + " \"description\": \"good\",\n" // + " \"rating\": 1.23\n" // + " },\n" // + " {\n" // + " \"lat\": 46.78185201,\n" // + " \"lng\": 23.68522613,\n" // + " \"type\": \"something not bad\",\n" // + " \"description\": \"not bad\",\n" // + " \"rating\": 3.99\n" // + " },\n" // + " {\n" // + " \"lat\": 46.7558097,\n" // + " \"lng\": 23.5940353,\n" // + " \"type\": \"something bad\",\n" // + " \"description\": \"bad\",\n" // + " \"rating\": 4.75\n" // + " }\n" // + " ]\n" // + "}"; JsonObject result = new JsonObject(); JsonArray featuresArr = new JsonArray(); JsonArray items = jsonObject.getJsonObject("hits").getJsonArray("hits"); for (Object hit : items) { JsonObject source = ((JsonObject) hit).getJsonObject("_source"); JsonObject feature = new JsonObject(); Float lon = source.getJsonObject("location").getFloat("lon"); Float lat = source.getJsonObject("location").getFloat("lat"); feature.put("lat", lat); feature.put("lng", lon); feature.put("type", source.getString("condition")); String symptoms = ""; int ratingSum = 0; int ratingCount = 0; JsonArray symptomsJ = source.getJsonArray("symptoms"); for (Object sym : symptomsJ) { JsonObject symJ = (JsonObject) sym; symptoms += symJ.getString("name") + ", "; ratingSum += symJ.getInteger("rating"); ratingCount++;//from w ww .j a va 2 s .c om } feature.put("description", symptoms); if (ratingCount > 0) { feature.put("rating", ratingSum / ratingCount); } else { feature.put("rating", 0); } featuresArr.add(feature); } result.put("Diseases", featuresArr); return result; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService save(JsonObject payload, Handler<AsyncResult<JsonArray>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }// w ww. ja v a 2 s . c om JsonObject _json = new JsonObject(); _json.put("payload", payload); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "save"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService query(String sql, Handler<AsyncResult<List<JsonObject>>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from ww w. ja va 2 s.c o m JsonObject _json = new JsonObject(); _json.put("sql", sql); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "query"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(convertList(res.result().body().getList()))); } }); return this; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService queryOne(String sql, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w w w . j a v a 2s.co m JsonObject _json = new JsonObject(); _json.put("sql", sql); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "queryOne"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService one(Long id, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/*w w w. ja va 2s. c o m*/ JsonObject _json = new JsonObject(); _json.put("id", id); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "one"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService findByUsername(String username, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w w w .j a v a 2s. c o m JsonObject _json = new JsonObject(); _json.put("username", username); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "findByUsername"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:com.panjiesw.std.service.user.UserServiceVertxEBProxy.java
License:Apache License
public UserService findByEmail(String email, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w ww . j a v a 2s .com JsonObject _json = new JsonObject(); _json.put("email", email); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "findByEmail"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:com.pluralsight.dockerproductionaws.portfolio.PortfolioConverter.java
License:Apache License
public static void toJson(Portfolio obj, JsonObject json) { json.put("cash", obj.getCash()); if (obj.getShares() != null) { JsonObject map = new JsonObject(); obj.getShares().forEach((key, value) -> map.put(key, value)); json.put("shares", map); }/* w w w . j av a 2 s .co m*/ }
From source file:com.pluralsight.dockerproductionaws.portfolio.PortfolioServiceVertxEBProxy.java
License:Apache License
public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/* w w w .j a v a2 s. c o m*/ } JsonObject _json = new JsonObject(); _json.put("amount", amount); _json.put("quote", quote); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "buy"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future .succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body()))); } }); }
From source file:com.pluralsight.dockerproductionaws.portfolio.PortfolioServiceVertxEBProxy.java
License:Apache License
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from www . j ava2 s .com*/ } JsonObject _json = new JsonObject(); _json.put("amount", amount); _json.put("quote", quote); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "sell"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future .succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body()))); } }); }