Gradle returns package does not exists [duplicate]

The accepted answer did not work for me, but this did: Download the GSON JAR file and copy it to your /libs/ folder inside your application project. Open the build.gradle file at the root level of your project and edit your dependencies to include the new .jar file: dependencies { compile fileTree(dir: ‘libs’, include: ‘*.jar’) … Read more

Using GSON to parse a JSON with dynamic “key” and “value” in android

The most straightforward approach I can think of is to just treat the structure as a Map (of Map). With Gson, this is relatively easy to do, as long as the Map structure is statically known, every branch from the root has the same depth, and everything is a String. import java.io.FileReader; import java.lang.reflect.Type; import … Read more

only classes are allowed on the left hand side of a class literal

You can’t use generics with class, as easily observable here: List<Int>::class.java It gives you the same error. To use the generic typ in GSON deserialization, do what is suggested here: https://stackoverflow.com/a/5554296/8073652 EDIT: In Kotlin it looks like this: val type: Type = object : TypeToken<ServiceCall<SurveyListModel>>() {}.type Gson().fromJson<ServiceCall<SurveyListModel>>(json, type).result Here’s a small proof of concept, I’ve … Read more

Using gson to deserialize specific JSON field of an object

When parsing such a simple structure, no need to have dedicated classes. Solution 1 : To get the imgurURL from your String with gson, you can do this : JsonParser parser = new JsonParser(); JsonObject obj = parser.parse(toExtract).getAsJsonObject(); String imgurl = obj.get(“imgurl”).getAsString(); This uses a raw parsing into a JsonObject. Solution 2 : Alternatively, you … Read more

How use Kotlin enum with Retrofit?

enum class VehicleEnumEntity(val value: String) { @SerializedName(“vehicle”) CAR(“vehicle”), @SerializedName(“motorcycle”) MOTORCYCLE(“motorcycle”), @SerializedName(“van”) VAN(“van”), @SerializedName(“motorhome”) MOTORHOME(“motorhome”), @SerializedName(“other”) OTHER(“other”) } Source

GSON Case-Insensitive Enum Deserialization

A simpler way I found (just now) to do this is to use the @SerializedName annotation. I found it in the EnumTest.java here (the Gender class around ln 195): https://code.google.com/p/google-gson/source/browse/trunk/gson/src/test/java/com/google/gson/functional/EnumTest.java?r=1230 This assumes that all of your Types will come in as lowercase as opposed to being “case insensitive” public enum Type { @SerializedName(“live”) LIVE, @SerializedName(“upcoming”) … Read more

How to decode JSON with unknown field using Gson?

(After OP commented that in fact the JSON looks like this, I completely updated the answer.) Solution for Gson 2.0+ I just learned that with newer Gson versions this is extremely simple: GsonBuilder builder = new GsonBuilder(); Object o = builder.create().fromJson(json, Object.class); The created object is a Map (com.google.gson.internal.LinkedTreeMap), and if you print it, it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)