List of usage examples for com.google.gson JsonArray get
public JsonElement get(int i)
From source file:at.maui.cheapcast.json.deserializer.ProtocolMessageDeserializer.java
License:Apache License
@Override public ProtocolMessage deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { ProtocolMessage pm;//from ww w.j av a 2 s . c o m if (jsonElement.isJsonArray()) { JsonArray arr = jsonElement.getAsJsonArray(); pm = new ProtocolMessage(); pm.setProtocol(arr.get(0).getAsString()); if (pm.getProtocol().equals("ramp")) { pm.setPayload((RampMessage) jsonDeserializationContext.deserialize(arr.get(1), RampMessage.class)); } else if (pm.getProtocol().equals("cm")) { pm.setPayload((CmMessage) jsonDeserializationContext.deserialize(arr.get(1), CmMessage.class)); } return pm; } return null; //To change body of implemented methods use File | Settings | File Templates. }
From source file:at.orz.arangodb.util.JsonUtils.java
License:Apache License
public static int[] toArray(JsonArray array) { int len = array.size(); int[] iarray = new int[len]; for (int i = 0; i < len; i++) { iarray[i] = array.get(i).getAsInt(); }//from ww w . j a va2s. c o m return iarray; }
From source file:at.orz.arangodb.util.JsonUtils.java
License:Apache License
public static double[] toDoubleArray(JsonArray array) { int len = array.size(); double[] darray = new double[len]; for (int i = 0; i < len; i++) { darray[i] = toDouble(array.get(i)); }/*w ww.j a va2s.c o m*/ return darray; }
From source file:augsburg.se.alltagsguide.common.EventCategory.java
License:Open Source License
@NonNull public static List<EventCategory> fromJson(@NonNull JsonArray array) { List<EventCategory> categories = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JsonObject obj = array.get(i).getAsJsonObject(); EventCategory category = fromJson(obj); if (category != null) { categories.add(category);//w w w . jav a 2 s . c o m } } return categories; }
From source file:augsburg.se.alltagsguide.common.EventTag.java
License:Open Source License
@NonNull public static List<EventTag> fromJson(@NonNull JsonArray array) { List<EventTag> tags = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { EventTag tag = fromJson(array.get(i).getAsJsonObject()); tags.add(tag);// ww w . j av a2 s. c om } return tags; }
From source file:augsburg.se.alltagsguide.serialization.EventPageSerializer.java
License:Open Source License
@NonNull private List<EventPage> getPagesByParentId(final EventPage parent, final int parentId, @NonNull final JsonArray jsonPages) { final List<EventPage> result = new ArrayList<>(); for (int i = 0; i < jsonPages.size(); i++) { JsonObject jsonPage = jsonPages.get(i).getAsJsonObject(); if (jsonPage.get("parent").getAsInt() == parentId) { EventPage page = EventPage.fromJson(jsonPage); page.setParent(parent);// w w w.java 2 s.c o m result.add(page); } } return result; }
From source file:augsburg.se.alltagsguide.serialization.LanguageSerializer.java
License:Open Source License
@NonNull private List<Language> parseLanguages(@NonNull final JsonArray jsonPages) { List<Language> Languages = new ArrayList<>(); for (int i = 0; i < jsonPages.size(); i++) { Languages.add(Language.fromJson(jsonPages.get(i).getAsJsonObject())); }/*w w w.j a v a 2s. c o m*/ return Languages; }
From source file:augsburg.se.alltagsguide.serialization.LocationSerializer.java
License:Open Source License
@NonNull private List<Location> parseLocations(@NonNull final JsonArray jsonPages) { List<Location> locations = new ArrayList<>(); for (int i = 0; i < jsonPages.size(); i++) { locations.add(Location.fromJson(jsonPages.get(i).getAsJsonObject())); }/*from w w w . j a v a 2 s.c o m*/ return locations; }
From source file:augsburg.se.alltagsguide.serialization.PageSerializer.java
License:Open Source License
private List<Page> parsePages(@NonNull final JsonArray jsonPages) { List<Page> pages = new ArrayList<>(); for (int i = 0; i < jsonPages.size(); i++) { pages.add(Page.fromJson(jsonPages.get(i).getAsJsonObject())); }/*from w ww.j a v a2 s. co m*/ return pages; }
From source file:be.iminds.iot.dianne.dataset.DatasetConfigurator.java
License:Open Source License
private void parseDatasetConfiguration(File f) { try {//from w ww. j av a 2 s. c om // parse any adapter configurations from JSON and apply config? JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new JsonReader(new FileReader(f))).getAsJsonObject(); String name = json.get("name").getAsString(); if (name == null) return; // should have a name Hashtable<String, Object> props = new Hashtable<>(); String dir = f.getParentFile().getAbsolutePath(); props.put("dir", dir); String pid = null; if (json.has("adapter")) { String adapter = json.get("adapter").getAsString(); pid = adapter.contains(".") ? adapter : "be.iminds.iot.dianne.dataset.adapters." + adapter; // in case of adapter, set Dataset target: the dataset it is adapting String dataset = json.get("dataset").getAsString(); props.put("Dataset.target", "(name=" + dataset + ")"); } else if (json.has("type")) { String type = json.get("type").getAsString(); pid = "be.iminds.iot.dianne.dataset." + type; } else { // some hard coded pids if (name.startsWith("MNIST")) { pid = "be.iminds.iot.dianne.dataset.MNIST"; } else if (name.startsWith("CIFAR-100")) { pid = "be.iminds.iot.dianne.dataset.CIFAR100"; } else if (name.startsWith("CIFAR-10")) { pid = "be.iminds.iot.dianne.dataset.CIFAR10"; } else if (name.startsWith("STL-10")) { pid = "be.iminds.iot.dianne.dataset.STL10"; } else if (name.startsWith("SVHN")) { pid = "be.iminds.iot.dianne.dataset.SVHN"; } else if (name.equalsIgnoreCase("ImageNetValidation")) { pid = "be.iminds.iot.dianne.dataset.ImageNet.validation"; } else if (name.equalsIgnoreCase("ImageNetTraining")) { pid = "be.iminds.iot.dianne.dataset.ImageNet.training"; } else { pid = "be.iminds.iot.dianne.dataset." + name; } } // set an aiolos instance id using the dataset name to treat // equally named datasets as single instance in the network props.put("aiolos.instance.id", name); // combine all offered interfaces (might be SequenceDataset or ExperiencePool) props.put("aiolos.combine", "*"); // TODO use object conversion from JSON here? Configuration config = ca.createFactoryConfiguration(pid, null); json.entrySet().stream().forEach(e -> { if (e.getValue().isJsonArray()) { JsonArray a = e.getValue().getAsJsonArray(); String[] val = new String[a.size()]; for (int i = 0; i < val.length; i++) { val[i] = a.get(i).getAsString(); } props.put(e.getKey(), val); } else { props.put(e.getKey(), e.getValue().getAsString()); } }); config.update(props); } catch (Exception e) { System.err.println("Error parsing Dataset config file: " + f.getAbsolutePath()); e.printStackTrace(); } }