List of usage examples for com.google.gson JsonObject entrySet
public Set<Map.Entry<String, JsonElement>> entrySet()
From source file:algorithmi.models.Institutions.java
public Institutions(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject institutions = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(institutions.entrySet()); //Revalidar TUDO, formatos, campos vazios, TUDO!! validateData();//from w w w. ja v a 2 s.c om //TEM DE IR BUSCAR O ULTIMO ID E ACRESCENTAR UM this._id = 123; this.name = institutions.get("name").getAsString(); this.address = institutions.get("address").getAsString(); }
From source file:algorithmi.Models.Question.java
License:Apache License
public Question(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject Question = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(Question.entrySet()); /**//w w w.j a v a2 s .co m * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto Question this._id = 123; //ir buscar o max id da bd + 1 this.title = Question.get("titulo").getAsString(); this.category = Question.get("categoria").getAsInt(); this.description = Question.get("descricao").getAsString(); this.image = Question.get("imagem").getAsString(); this.algorithm = Question.get("algoritmo").getAsString(); }
From source file:algorithmi.models.QuestionIO.java
public QuestionIO(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject QuestionIO = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(QuestionIO.entrySet()); /**/* w w w .j av a2 s . c o m*/ * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto Question this._id = 123; //ir buscar o max id da bd + 1 this.question = QuestionIO.get("titulo").getAsInt(); this.in = QuestionIO.get("in").getAsString(); this.out = QuestionIO.get("out").getAsString(); }
From source file:algorithmi.models.Schools.java
public Schools(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject schools = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(schools.entrySet()); //Revalidar TUDO, formatos, campos vazios, TUDO!! validateData();//from w w w. ja va2 s. c o m //TEM DE IR BUSCAR O ULTIMO ID E ACRESCENTAR UM this._id = 123; this.name = schools.get("name").getAsString(); this.institution = schools.get("institution").getAsInt(); }
From source file:algorithmi.models.TypeUser.java
License:Apache License
public TypeUser(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject UserType = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(UserType.entrySet()); /**/* w ww .ja v a 2 s .c om*/ * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto UserType this.id_Type = UserType.getAsInt(); //ir buscar o max id da bd + 1 this.name = UserType.get("name").getAsString(); // }
From source file:algorithmi.models.User.java
License:Apache License
public User(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject user = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(user.entrySet()); /**//w w w . j ava2 s. co m * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto User this._id = 123; //ir buscar o max id da bd + 1 this.name = user.get("name").getAsString(); // this.password = user.get("password").getAsString(); this.imgB64 = user.get("imgB64").getAsString(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); df.setLenient(false); Date dt; try { dt = df.parse(user.get("dateBirth").getAsString()); } catch (ParseException ex) { dt = new Date(); } this.dateBirth = dt; this.email = user.get("email").getAsString(); this.type = 3;//Definir o tipo de utilizador, como registo, dever ser do tipo aluno }
From source file:algorithmi.models.UserCourse.java
License:Apache License
public UserCourse(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject UserCourse = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(UserCourse.entrySet()); /**/*from w w w . j av a2 s. co m*/ * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto UserCourse this.user = UserCourse.get("_id").getAsInt(); ; //ir buscar o max id da bd + 1 this.course = UserCourse.get("codCourse").getAsInt(); }
From source file:angularBeans.remote.InvocationHandler.java
License:LGPL
private void update(Object o, JsonObject params) { if (params != null) { // boolean firstIn = false; for (Map.Entry<String, JsonElement> entry : params.entrySet()) { JsonElement value = entry.getValue(); String name = entry.getKey(); if ((name.equals("sessionUID")) || (name.equals("args"))) { continue; }/* w w w.ja v a2 s .c o m*/ if ((value.isJsonObject()) && (!value.isJsonNull())) { String getName; try { getName = CommonUtils.obtainGetter(o.getClass().getDeclaredField(name)); Method getter = o.getClass().getMethod(getName); Object subObj = getter.invoke(o); // logger.log(Level.INFO, "#entring sub object "+name); update(subObj, value.getAsJsonObject()); } catch (NoSuchFieldException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } } // ------------------------------------ if (value.isJsonArray()) { try { String getter = CommonUtils.obtainGetter(o.getClass().getDeclaredField(name)); Method get = o.getClass().getDeclaredMethod(getter); Type type = get.getGenericReturnType(); ParameterizedType pt = (ParameterizedType) type; Type actType = pt.getActualTypeArguments()[0]; String className = actType.toString(); className = className.substring(className.indexOf("class") + 6); Class clazz = Class.forName(className); JsonArray array = value.getAsJsonArray(); Collection collection = (Collection) get.invoke(o); Object elem; for (JsonElement element : array) { if (element.isJsonPrimitive()) { JsonPrimitive primitive = element.getAsJsonPrimitive(); elem = element; if (primitive.isBoolean()) elem = primitive.getAsBoolean(); if (primitive.isString()) { elem = primitive.getAsString(); } if (primitive.isNumber()) elem = primitive.isNumber(); } else { elem = util.deserialise(clazz, element); } try { if (collection instanceof List) { if (collection.contains(elem)) collection.remove(elem); } collection.add(elem); } catch (UnsupportedOperationException e) { Logger.getLogger("AngularBeans").log(java.util.logging.Level.WARNING, "trying to modify an immutable collection : " + name); } } } catch (Exception e) { e.printStackTrace(); } } // ------------------------------------------ if (value.isJsonPrimitive() && (!name.equals("setSessionUID"))) { try { if (!CommonUtils.hasSetter(o.getClass(), name)) { continue; } name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Class type = null; for (Method set : o.getClass().getDeclaredMethods()) { if (CommonUtils.isSetter(set)) { if (set.getName().equals(name)) { Class<?>[] pType = set.getParameterTypes(); type = pType[0]; break; } } } if (type.equals(LobWrapper.class)) continue; Object param = null; if ((params.entrySet().size() >= 1) && (type != null)) { param = CommonUtils.convertFromString(value.getAsString(), type); } o.getClass().getMethod(name, type).invoke(o, param); } catch (Exception e) { e.printStackTrace(); } } } } }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.type.json.JsonMapTypeAdapter.java
License:Apache License
@Override public Map<?, ?> deserialize(JsonElement element, TypeMetadata<JsonElement> typeMetadata) { JsonObject jsonObject = (JsonObject) element; TypeAdapter valueTypeAdapter = typeMetadata.getTypeParameterTypeAdapters().get(1); Map<Object, Object> map = new HashMap<Object, Object>(); for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { PropertyEditor editor = PropertyEditorManager.findEditor(typeMetadata.getTypeParameterTypes().get(0)); editor.setAsText(entry.getKey()); Object key = editor.getValue(); Object value = valueTypeAdapter.deserialize(entry.getValue(), typeMetadata); map.put(key, value);/*from w w w . java2s.co m*/ } return map; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private Map<Long, User> json2Users(JsonObject json) { HashMap<Long, User> users = new HashMap<Long, User>(); JsonObject block = json.get(SECTION_U).getAsJsonObject(); Set<Entry<String, JsonElement>> entries = block.entrySet(); for (Entry<String, JsonElement> u : entries) { JsonObject jsUser = u.getValue().getAsJsonObject(); System.out.println(jsUser.toString()); String uname;/*ww w.j a v a 2s .co m*/ if (jsUser.has(NAME)) uname = jsUser.get(NAME).getAsString(); else uname = ""; String uDescr; if (jsUser.has(DESCRIPTION)) uDescr = jsUser.get(DESCRIPTION).getAsString(); else uDescr = ""; String externalUID; if (jsUser.has(E_UID)) externalUID = jsUser.get(E_UID).getAsString(); else externalUID = ""; User user = new User(externalUID, uname, uDescr); users.put(Long.parseLong(u.getKey()), user); } return users; }