List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:at.gv.egovernment.moa.id.protocols.oauth20.OAuth20Util.java
License:EUPL
public static void addProperytiesToJsonObject(JsonObject jsonObject, Map<String, Object> params) { for (Map.Entry<String, Object> param : params.entrySet()) { if (!StringUtils.isEmpty(param.getKey()) && param.getValue() != null) { // check for integer try { int i = Integer.parseInt(String.valueOf(param.getValue())); jsonObject.addProperty(param.getKey(), i); continue; } catch (NumberFormatException e) { }/*www . java2s. com*/ // check for long try { long l = Long.parseLong(String.valueOf(param.getValue())); jsonObject.addProperty(param.getKey(), l); continue; } catch (NumberFormatException e) { } // string if (param.getValue() instanceof String) { jsonObject.addProperty(param.getKey(), String.valueOf(param.getValue())); } } } }
From source file:at.orz.arangodb.impl.InternalGraphDriverImpl.java
License:Apache License
public <T> EdgeEntity<T> createEdge(String database, String graphName, String key, String fromHandle, String toHandle, Object value, String label, Boolean waitForSync) throws ArangoException { JsonObject obj; if (value == null) { obj = new JsonObject(); } else {/* ww w.j a v a 2s . c o m*/ JsonElement elem = EntityFactory.toJsonElement(value, false); if (elem.isJsonObject()) { obj = elem.getAsJsonObject(); } else { throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); } } obj.addProperty("_key", key); obj.addProperty("_from", fromHandle); obj.addProperty("_to", toHandle); obj.addProperty("$label", label); validateCollectionName(graphName); HttpResponseEntity res = httpManager.doPost( createEndpointUrl(baseUrl, database, "/_api/graph", StringUtils.encodeUrl(graphName), "/edge"), new MapBuilder().put("waitForSync", waitForSync).get(), EntityFactory.toJsonString(obj)); return createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); }
From source file:at.storm.bolt.JsonBolt.java
License:Apache License
public void execute(Tuple tuple, BasicOutputCollector collector) { String jsonString = tuple.getStringByField("jsonString"); TupleStatistic tupleStatistic = (TupleStatistic) tuple.getValueByField("tupleStatistic"); JsonObject jsonObject = (JsonObject) jsonParser.parse(jsonString); if (m_logging) { LOG.info("JSON: " + jsonObject.toString()); }//from w w w .ja va2s . c o m tupleStatistic.setRealStart(jsonObject.get("timestamp").getAsLong()); String message = jsonObject.get("msg").getAsString(); if (!LanguageDetection.isEnglish(message)) { JsonObject score = new JsonObject(); score.addProperty("score", 0); jsonObject.add("sentiment", score); collector.emit(TO_REDIS_PUBLISH_STREAM, new JsonBoltData(jsonObject, tupleStatistic)); } else { collector.emit(PIPELINE_STREAM, new JsonBoltData(jsonObject, tupleStatistic)); } }
From source file:at.storm.bolt.SVMBolt.java
License:Apache License
public void execute(Tuple tuple) { FeatureGenerationBoltData featureGenerationValue = FeatureGenerationBoltData.getFromTuple(tuple); JsonObject jsonObject = featureGenerationValue.getJsonObject(); TupleStatistic tupleStatistic = featureGenerationValue.getTupleStatistic(); Map<Integer, Double> featureVector = featureGenerationValue.getFeatureVector(); // Create feature nodes svm_node[] testNodes = new svm_node[featureVector.size()]; int i = 0;/*from w w w.ja v a 2 s . c o m*/ for (Map.Entry<Integer, Double> feature : featureVector.entrySet()) { svm_node node = new svm_node(); node.index = feature.getKey(); node.value = feature.getValue(); testNodes[i] = node; i++; } double predictedClass = svm.svm_predict(m_model, testNodes); JsonObject score = new JsonObject(); score.addProperty("score", convertRating(predictedClass)); jsonObject.add("sentiment", score); if (m_logging) { LOG.info("SVM all done log: " + jsonObject.toString()); } collector.emit(tuple, new SVMBoltData(jsonObject, tupleStatistic)); collector.ack(tuple); }
From source file:at.tugraz.kmi.medokyservice.fca.db.DataObject.java
License:Open Source License
/** * Returns a JSON string representation of the object using the * {@link JSONMapper}// w w w . ja v a 2s . c om * * @return a JSON string representation of the object */ @Override public String toString() { try { return JSONMapper.getInstance().toJson(this); } catch (Exception e) { JsonObject js = new JsonObject(); js.addProperty("id", id); js.addProperty("name", name); js.addProperty("description", description); return js.toString(); } }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private static JsonObject prepare(DataObject o) { JsonObject jso = new JsonObject(); jso.addProperty(ID, o.getId()); jso.addProperty(NAME, o.getName());/*from w w w . j a v a 2s .c o m*/ jso.addProperty(DESCRIPTION, o.getDescription()); return jso; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement users2JSON() { BlockingDeque<User> users = Database.getInstance().getAll(User.class); JsonObject block = new JsonObject(); for (User u : users) { JsonObject jso = prepare(u); jso.addProperty(E_UID, u.getExternalUid()); block.add(Long.toString(u.getId()), jso); }//from w w w . ja va 2s .c om return block; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement learningObjects2JSON() { BlockingDeque<LearningObject> lobjects = Database.getInstance().getAll(LearningObject.class); JsonObject block = new JsonObject(); for (LearningObject o : lobjects) { JsonObject jso = prepare(o); jso.addProperty(DATA, o.getData()); jso.addProperty(OWNER, o.getOwner().getId()); block.add(Long.toString(o.getId()), jso); }// w w w . j a v a 2 s . com return block; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private <E extends FCAAbstract> JsonElement abstracts2JSon(Class<E> type) { BlockingDeque<E> objects = Database.getInstance().getAll(type); JsonObject block = new JsonObject(); for (E o : objects) { JsonObject jso = prepare(o); jso.addProperty(CID, o.getCreationId()); LinkedList<Long> loIds = new LinkedList<Long>(); LinkedList<Long> loByLearnerIds = new LinkedList<Long>(); for (LearningObject lo : o.getLearningObjects()) { loIds.add(lo.getId());// w ww . j a v a 2s . co m } for (LearningObject lo : o.getLearningObjectsByLearners()) { loByLearnerIds.add(lo.getId()); } jso.add(SECTION_LO, gson.toJsonTree(loIds, new TypeToken<List<Long>>() { }.getType())); jso.add(SECTION_LO_L, gson.toJsonTree(loByLearnerIds, new TypeToken<List<Long>>() { }.getType())); block.add(Long.toString(o.getId()), jso); } return block; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement metadata2JSON() { BlockingDeque<FCAItemMetadata> lobjects = Database.getInstance().getAll(FCAItemMetadata.class); JsonObject block = new JsonObject(); for (FCAItemMetadata o : lobjects) { JsonObject jso = prepare(o); jso.addProperty(O_ID, o.getItemID()); LinkedList<Long> loIds = new LinkedList<Long>(); for (LearningObject lo : o.getLearningObjects()) { if (lo != null) loIds.add(lo.getId());//from w ww . ja v a2s . c om } LinkedList<Long> loByLernerIds = new LinkedList<Long>(); for (LearningObject lo : o.getLearningObjectByLearner()) { if (lo != null) loByLernerIds.add(lo.getId()); } jso.add(SECTION_LO, gson.toJsonTree(loIds, new TypeToken<List<Long>>() { }.getType())); jso.add(SECTION_LO_L, gson.toJsonTree(loByLernerIds, new TypeToken<List<Long>>() { }.getType())); block.add(Long.toString(o.getId()), jso); } return block; }