Cannot import Gson into my JavaFX Maven project

I am working on a JavaFX Maven project in VSCode and am trying to import Gson into one of my classes and it’s not letting me. VSCode gives me a "The type com.google.gson.Gson is not accessible" error and refuses to let me work with Gson. The dependency has been added into my pom.xml file and… Read More Cannot import Gson into my JavaFX Maven project

(Kotlin) com.google.gson.internal.LinkedTreeMap cannot be cast to com.example.phonetest2.model.HallData

My data class: data class HallData( var name:String, var mobile:String, var isAddInfoChecked:Boolean, var isFanDetailChecked:Boolean, var fanNumber:String, var isPompDetailChecked:Boolean, var pompNumber:String, var isHeaterDetailChecked:Boolean, var heaterNumber:String, var isCircularFanDetailChecked:Boolean, var circularFanNumber:String ) UserAdapter: class UserAdapter(val c: Context, val userList: MutableList<HallData>) : RecyclerView.Adapter<UserAdapter.UserViewHolder>() { inner class UserViewHolder(val v: View) : RecyclerView.ViewHolder(v) { var name: TextView var mbNum: TextView var… Read More (Kotlin) com.google.gson.internal.LinkedTreeMap cannot be cast to com.example.phonetest2.model.HallData

How to fix Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

I have encountered a problem when I want to fetch my data to recyclerview using Java, and resulting in the problem: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $ My API Response : [ { "id": "1", "type": "Barang Elektronik", "payment_method": "Cash", "price": "500000", "date": "2023-07-11 00:00:00", "detail": "Charger… Read More How to fix Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

Convert JSON to MAP using GSON library

I want to convert JSON response to Map what is the best approach to get the desired output using GSON library. I try this and I’m getting only the ArrayList value. Map<String, Object> map = gson.fromJson(response, HashMap.class); ArrayList responseOptions = (ArrayList) map.get("data"); output: [{language=Java, value=8}, {language=Ruby, value=7}, {language=Python, value=7}] Sample JSON Response { "data":[ {… Read More Convert JSON to MAP using GSON library

How do I write a JSON file using GSON in the resources folder without using src/main/resources?

I’m trying to write a JSON file with GSON in the resources folder without using src/main/resources: package repository; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import org.tinylog.Logger; import java.io.*; import java.util.List; public class GsonRepository<T> extends Repository<T> { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public GsonRepository(Class<T> elementType) { super(elementType); } public void saveToFile(String resourceName) throws… Read More How do I write a JSON file using GSON in the resources folder without using src/main/resources?