List of usage examples for com.google.gson JsonElement getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive()
From source file:org.eclipse.smarthome.config.core.ConfigurationDeserializer.java
License:Open Source License
private Object deserialize(JsonArray array) { List<Object> list = new LinkedList<>(); for (JsonElement element : array) { if (element.isJsonPrimitive()) { JsonPrimitive primitive = element.getAsJsonPrimitive(); list.add(deserialize(primitive)); } else {// w w w . ja va2 s.c o m throw new IllegalArgumentException("Multiples must only contain primitives but was " + element); } } return list; }
From source file:org.eclipse.smarthome.storage.json.ConfigurationDeserializer.java
License:Open Source License
@Override public Configuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Configuration configuration = new Configuration(); JsonObject configurationObject = json.getAsJsonObject(); if (configurationObject.get("properties") != null) { JsonObject propertiesObject = configurationObject.get("properties").getAsJsonObject(); for (Entry<String, JsonElement> entry : propertiesObject.entrySet()) { JsonElement value = entry.getValue(); String key = entry.getKey(); if (value.isJsonPrimitive()) { JsonPrimitive primitive = value.getAsJsonPrimitive(); configuration.put(key, deserialize(primitive)); } else if (value.isJsonArray()) { JsonArray array = value.getAsJsonArray(); configuration.put(key, deserialize(array)); } else { throw new IllegalArgumentException( "Configuration parameters must be primitives or arrays of primities only but was " + value); }//ww w.ja v a2 s . c om } } return configuration; }
From source file:org.eel.kitchen.jsonschema.GsonProvider.java
License:Open Source License
private JsonNode gsonToJsonNode(final JsonElement element) { if (element.isJsonNull()) return factory.nullNode(); if (element.isJsonPrimitive()) return gsonToValueNode(element.getAsJsonPrimitive()); return element.isJsonArray() ? gsonToArrayNode(element) : gsonToObjectNode(element); }
From source file:org.faul.jql.utils.RemoteObjectHandler.java
License:Open Source License
public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String str = null;// www . j a va 2 s . c o m if (json instanceof JsonPrimitive) { str = json.getAsJsonPrimitive().getAsString(); JsonPrimitive p = (JsonPrimitive) json; return getPrimitive(p); } if (json instanceof JsonArray) { JsonArray array = (JsonArray) json; return getList(array); } if (json instanceof JsonObject) { // Now we will assume its a map JsonObject jso = json.getAsJsonObject(); Map map = new HashMap(); mapHandler(map, jso); return map; } throw new JsonParseException("Can't handle: " + json); }
From source file:org.fedoraproject.eclipse.packager.bodhi.deserializers.DateTimeDeserializer.java
License:Open Source License
@Override public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new DateTime(json.getAsJsonPrimitive().getAsString()); }
From source file:org.fenixedu.cms.domain.PermissionsArray.java
License:Open Source License
public static PermissionsArray fromJson(JsonElement json) { List<Permission> permissionList = new ArrayList<>(); for (JsonElement permissionJson : json.getAsJsonArray()) { permissionList.add(Permission.valueOf(permissionJson.getAsJsonPrimitive().getAsString())); }// www . j ava 2 s . com return new PermissionsArray(EnumSet.copyOf(permissionList)); }
From source file:org.gdg.frisbee.android.api.deserializer.DateTimeDeserializer.java
License:Apache License
@Override public DateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { //DateTimeFormatter fmt = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ssZZ"); //2013-05-15T16:30:00+02:00 DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MMM YYYY HH:mm Z").withLocale(Locale.ENGLISH); // 04 Jul 2013 23:00 +0200 return fmt.parseDateTime(jsonElement.getAsJsonPrimitive().getAsString()); }
From source file:org.gdg.frisbee.android.api.deserializer.ZuluDateTimeDeserializer.java
License:Apache License
@Override public DateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return DATE_TIME_FORMATTER.parseDateTime(jsonElement.getAsJsonPrimitive().getAsString()); }
From source file:org.gdg.frisbee.android.cache.ModelCacheDateTimeDeserializer.java
License:Apache License
@Override public DateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { DateTimeFormatter fmt = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss.SSS'Z'").withLocale(Locale.US); return fmt.parseDateTime(jsonElement.getAsJsonPrimitive().getAsString()); }
From source file:org.geogit.web.api.repo.BatchedObjectResource.java
License:Open Source License
@Override protected Representation post(Representation entity) throws ResourceException { try {//from w ww . j a v a2 s . com final Reader body = entity.getReader(); final JsonParser parser = new JsonParser(); final JsonElement messageJson = parser.parse(body); final List<ObjectId> want = new ArrayList<ObjectId>(); final List<ObjectId> have = new ArrayList<ObjectId>(); if (messageJson.isJsonObject()) { final JsonObject message = messageJson.getAsJsonObject(); final JsonArray wantArray; final JsonArray haveArray; if (message.has("want") && message.get("want").isJsonArray()) { wantArray = message.get("want").getAsJsonArray(); } else { wantArray = new JsonArray(); } if (message.has("have") && message.get("have").isJsonArray()) { haveArray = message.get("have").getAsJsonArray(); } else { haveArray = new JsonArray(); } for (final JsonElement e : wantArray) { if (e.isJsonPrimitive()) { want.add(ObjectId.valueOf(e.getAsJsonPrimitive().getAsString())); } } for (final JsonElement e : haveArray) { if (e.isJsonPrimitive()) { have.add(ObjectId.valueOf(e.getAsJsonPrimitive().getAsString())); } } } final GeoGIT ggit = (GeoGIT) getApplication().getContext().getAttributes().get("geogit"); final Repository repository = ggit.getRepository(); final Deduplicator deduplicator = ggit.command(CreateDeduplicator.class).call(); return new BinaryPackedObjectsRepresentation(new BinaryPackedObjects(repository.getObjectDatabase()), want, have, deduplicator); } catch (IOException e) { throw new RuntimeException(e); } }