Retrofit 2 example tutorial but GsonConverterFactory display error “Cannot resolve symbol”

EDIT retrofit 2 is now stable. Use compile ‘com.squareup.retrofit2:retrofit:2.3.0’ compile ‘com.squareup.retrofit2:converter-gson:2.3.0’ in your build.gradle dependency section old answer with Retrofit 2.0 you have to declare in your build.gradle the convert factory you want to use. Add compile ‘com.squareup.retrofit:converter-gson:2.0.0-beta2’ to your gradle and sync it again

Iterate over JsonObject properties

You can use entrySet to iterate over the members of the outermost JsonObject. JsonObject object; ArrayList<Integer> codes = new ArrayList<Integer>(); for (Map.Entry<String,JsonElement> entry : object.entrySet()) { JsonArray array = entry.getValue().getAsJsonObject().getAsJsonArray(“unterfeld”); for (JsonElement codeHolder : array) { codes.add(codeHolder.getAsJsonObject().getAsJsonPrimitive(“code”).getAsInt()); } }

How to convert List to a JSON Object using GSON?

There is a sample from google gson documentation on how to actually convert the list to json string: Type listType = new TypeToken<List<String>>() {}.getType(); List<String> target = new LinkedList<String>(); target.add(“blah”); Gson gson = new Gson(); String json = gson.toJson(target, listType); List<String> target2 = gson.fromJson(json, listType); You need to set the type of list in toJson … Read more

Deserializing an abstract class in Gson

I’d suggest adding a custom JsonDeserializer for Nodes: Gson gson = new GsonBuilder() .registerTypeAdapter(Node.class, new NodeDeserializer()) .create(); You will be able to access the JsonElement representing the node in the deserializer’s method, convert that to a JsonObject, and retrieve the field that specifies the type. You can then create an instance of the correct type … Read more

Java Date to UTC using gson

After some further research, it appears this is a known issue. The gson default serializer always defaults to your local timezone, and doesn’t allow you to specify the timezone. See the following link….. https://code.google.com/p/google-gson/issues/detail?id=281 The solution is to create a custom gson type adaptor as demonstrated in the link: // this class can’t be static … Read more

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