Most voted "gson" questions
Gson is a Java library that can be used to convert Java objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you don’t have the source code for. If the question is not about "GSON", do not use this tag, even if you are using "GSON" in your project.
Learn more…67 questions
Sort by count of
-
15
votes1
answer637
viewsHow to find where is the circular reference in GSON?
Imagine that I have these classes: public class A { private B b; } public class B { private A a; } And then I have this: A a = new A(); B b = new B(); a.b = b; b.a = a; Gson gson = new Gson();…
-
5
votes1
answer353
viewsHow to deserialize a list with items of type { "key": "value" }?
I need to deserialize a JSON, but I can’t map the enumerated object. Follows the JSON: { "list": [ { "1": "Bola" }, { "2": "Quadrado" }, { "3": "Retangulo" } ], "code": 0, "success": true } My…
-
5
votes1
answer147
viewsGson to Java - Map
I need to pass these values from a json file to a java class file, the Json file is of this type: { "id":1, "name":"Gold", "description":"Shiny!", "spriteId":1, "consumable":true, "effectsId":[1] },…
-
3
votes1
answer1336
viewsHow to deserialize JSON using Gson with generic list?
I need to deserialize JSON for a generic list, but I’m having an error that I believe is in the conversion: Method call: AtualizarJSON at = (AtualizarJSON) DeserializaConsulta(AtualizarJSON.class,…
-
3
votes1
answer339
viewsSend an object using Gson
I have the following problem: I need to send an object to my web-service, but it is not feasible to use Jsonstringer, because my class has many fields. What would be the best way to solve this…
-
3
votes1
answer6183
viewsHow to transform JSON into object array of a specific class, where this class has composite attributes?
I found the following problem when trying to transform a String JSON in object list. I have the following situation: I have a class Response which has some attributes, among them a list of "Post",…
-
3
votes2
answers103
viewsString deserialization
I caught the Retrofit Drivers field from the following json: { "Drivers": [ { "DriverID": 0, "Latitude": -23.642276336, "Longitude": -46.634615118 }, { "DriverID": 1, "Latitude": -23.64227916,…
-
3
votes1
answer2946
viewsHow to transform this Json into an object Arraylist?
I am working on a project where I am doing a database query and need to return a list of users from the database to be listed in my application. I have the following Json line (returned by the…
-
3
votes1
answer2872
viewsHow do I verify that a given field/value exists in the JSON document?
{ "timestamp":"2018-10-08T16:58:38.949Z", "dataFrame":"QQ==", "fcnt":15, "freq":902500000, "port":12, "rssi":-69, "snr":10, "sf_used":10, "session_id":"f41e10e8-1c73-499c-8ad7-4cbcd54c8ebd",…
-
2
votes2
answers2352
viewsError building JSON of an Object recovered by Hibernate
Error building Json of an Object recovered by Hibernate. session.getTransaction().begin(); ArrayList<Cliente> lista = new ArrayList<>(session.createCriteria(Cliente.class).list());…
-
2
votes0
answers264
viewsInclude and remove elements from a Json with lib Gson (Java)
I am using the Gson library in Java, I have the following structure in a json file: {"idAluno":4, "nomeAluno":"Teste da Silva", "listaDeTurmas":[1,2,4]} Is it possible, with this library, to change…
-
2
votes1
answer78
viewsGson Return Array of One Position
Hello I have the method : @RequestMapping("/olaMundo") public String iniciando(Model model, Cadastro cadastro){ CadastroDAO dao = new CadastroDAO(); dao.adiciona(cadastro);…
-
2
votes0
answers206
viewsGson Does Not Convert List to Json
Every time I try to pull all data from a database table and convert the result to json, using Gson, gives error. @GET @Path("todos") public String todos() { Gson g = new Gson(); UsuarioRepository…
-
2
votes1
answer680
viewsGson Library Changing useful. Date
When using the library GSON for the manipulation of JSON, I realized that by doing the parsers the date is being changed, it’s tiny, but it’s enough to break my unit test with JUnit. Follow a sketch…
-
2
votes1
answer807
viewsManipulating a JSON with the GSON library
This is the json: { "professor": [ { "latitude": -23.1843473, "longitude": -45.8840718, "title": "Microcamp", "endereco": "rua vilaça 2010" }, { "latitude": -23.1843473, "longitude": -45.8840718,…
-
1
votes1
answer162
viewsHow to deserialize a geometric polygon with Gson?
I am using Vraptor 4 and the intention is to create a converting class of Polygon that does the deserialization and serializes. My problem is only in deserialize. How to deserialize a geometric…
-
1
votes1
answer376
viewsConvert JSON to GSON object
I have a webservice ready, which returns a JSON of an object, great, working: Here is the returned JSON: {"Opa":{"nome":"Teste1234"}} This Json is of the following class: public class Opa { public…
-
1
votes0
answers76
views@Skipserialization
I’m having a problem serializing my classes. I have a circular reference problem, so I’m trying to treat this by adding the @Skipserialization annotation to the class to prevent it from being…
-
1
votes1
answer151
viewsPreventing an attribute from being serialized or deserialized
I am using Gson on a web service and need to prevent some attributes from being serialized and others that are prevented from being deserialized. One of the reasons to prevent serialization is due…
-
1
votes1
answer267
viewsError sending Arraylist via POST in Retrofit 2: java.lang.Illegalstateexception: Expected BEGIN_ARRAY but was STRING
When I try to send an Arraylist via @POST to be saved to my webserver with Retrofit2, Arraylist is saved, but I am getting the following error: java.lang.Illegalstateexception: Expected BEGIN_ARRAY…
-
1
votes1
answer82
viewsError searching for Information in Sharedpreferences Android
I have an android application, and in it I keep some basic user information in Sharedpreferences, but started to show the following error parse JSON: java.lang.Illegalstateexception: Expected…
-
1
votes1
answer675
viewsRead json with GSON library
How do I read this code with the GSON library? { "profissao": { "jornalista": [ "escritor", "legal", "fotografo" ], "programador": [ "focado", "exatas", "articulado" ], "maquinista": [ "senai",…
-
1
votes2
answers2942
viewsHow to read the json below with the GSON library
How to read the json below creating the professional class through the instances of the class I would like it to be in GSON without using HashMap - KeySet(); { "profissao": { "jornalista": […
-
1
votes2
answers63
viewsConflict when using Gson + Facebook API
Talk guys, all right? Someone there has used the Gson library in the same project where the Facebook SDK was used? The problem happened when I used the Facebook SDK to allow logging into the…
-
1
votes0
answers345
viewsGson returning characters with invalid accent
I’m getting information using Gson in an archive PHP. When this information is received, the words containing accents are not coded. I have read: Android JSON Charset UTF-8 problems Converting…
-
1
votes1
answer683
viewsGson: Jsonobject to Jsonarray conversion error (Jsonprimitive cannot be cast to com.google.gson.Jsonarray)
I am trying to convert a Jsonobject item into an Arraylist and for that I created this function from an example I saw here in the forum: public static ArrayList<Produto> converte(JSONObject…
-
1
votes1
answer648
viewsExtract data from JSON within JSON that they see from a Web Service serving an Android APP
Good night, guys, how are you? I am developing an Android APP and it consumes data from a webservice, but I’m having trouble bringing some information to the APP. This is the JSON I return to my…
-
1
votes0
answers187
viewsPagination with GSON (ANDROID)
Staff need to load when arriving at the end of the list, example I have 20 items, when arriving at the end of it, need to be loaded 20 more. Currently my Fragment loading the ads is as follows…
-
1
votes1
answer269
viewsHow to pass a class as a parameter in another class and return a variable that is within a Thread
I work with Delphi and I decided to learn how to make java applications, and I came across a problem. I have this class public class Dados { public void getJson(final String url) { new Thread(new…
-
1
votes2
answers461
viewsConvert JSON to Array in java
I have a JSON that represents a test query: {"dctitle":"TestesStatus", "oslc_cmtotalCount":2, "oslc_cmresults": [ {"dctitle":"33643640", "rdfabout":"XXXXXXXXXXX", "dbid":"XXXXXXXXXXX",…
-
1
votes1
answer566
viewsAccess a JSON key
I am making a POST request for my Webservice and am getting as a result a Json, I would like to pick a specific field of Json, because the key names are fixed ex: "campo1, campo2,campo3"... and so…
-
1
votes1
answer341
viewsConverting JSON to android arraylist
Good afternoon! I’m trying to consume an API on android but I’m having difficulty because in the JSON file it brings a category, I tried to add the variable "acronym" but it did not work; the JSON…
-
1
votes1
answer53
viewsHow to filter to show only required fields in a class using Gson
I’m using Gson to work with json, let’s say I have this class class Track( @SerializedName("id") val id: Long, @SerializedName("name") val name: String, @SerializedName("modality") val modality:…
-
1
votes1
answer104
viewsHow to answer a json using Gson
First of all, I agree that the question has gotten a little strange, but I can’t write my question otherwise. At the end of the explanation of the problem if someone wants to suggest a better title…
-
1
votes1
answer96
viewsValues with different types Gson - Java
I wonder, if there is a way with Gson to get values of different types in a "key-value" array in Json. Follow the example: { "events":[ {"event":"comprou-produto",…
-
1
votes1
answer1026
viewsConvert Java object to JSON with Gson (generating with backslash)
I am trying to generate a JSON based on a Java object. JSON is being generated, but some bars have been included improperly: import java.io.Serializable; import…
-
1
votes1
answer1117
viewsError converting JSON. (com.google.gson.stream.Malformedjsonexception)
I am developing a program that needs to communicate with an online store, all communication is done via HTTP requests and has as response a JSON. Displays the error…
-
1
votes1
answer2449
viewscom.google.gson.Jsonsyntaxexception: java.lang.Illegalstateexception: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
Hi, I’m new here and I’d like a hand. I happen to be developing a work of distributed systems in which the client is in Java and the server in Python. For there to be communication between the two,…
-
0
votes2
answers568
viewsGson: serialization of dates in various formats
I am using Gson and need to serialize a class with different date formats: @TimeStampField(onlyDate = false) private Timestamp datahora @TimeStampField(onlyDate = true) private Timestamp diaLimite I…
-
0
votes1
answer104
viewsError in retrofit2 convert-gson:2.1.0
I’m having a very persistent error in Retrofit2 this with line error GsonConverterFactory.create() I’ve tried a lot of things and I can’t make it spin. Retrofit retrofit = new Retrofit.Builder()…
-
0
votes1
answer1289
viewsHow to take received data in JSON and store in a class
Good afternoon! I am having difficulty implementing code to rescue the data that is coming in JSON and store this data in a class. If anyone can help me, I’d appreciate it. My idea is to receive the…
-
0
votes1
answer111
viewsProblem using Gson in Wildfly
I am trying to use GSON in a Maven EJB project but gives the following error: java.lang.NoClassDefFoundError: com/google/gson/Gson When I test in class main without uploading the server to lib works…
-
0
votes1
answer80
viewsHttp access via gson with parameters
In my first investment in android development, I came across the following need. I need to create a login screen by accessing the one address and capturing the gson return below. How could I do?…
-
0
votes1
answer255
viewsUsing Gson instead of Jackson in web service that makes use of Jersey
I found out that Jersey by default makes use of the Jackson framework for resources to return data in Json format. However, I had the need to use the Gson framework to convert objects to Json. How…
-
0
votes1
answer581
viewsDeserialize JSON with dynamic field names
I have a Json like this, and within the entity "purchase", I receive an object with the purchase id, and then the information I need to access, I have already generated the classes, however my…
-
0
votes1
answer116
viewsError "[ ] cannot be converted to JSON" when trying to create Jsonobject from String
I am using the Kotlin language together with the GSON library to perform JSON object creation/parse. I have the following string that caches a JSON object returned from a server val jsonString =…
-
0
votes2
answers715
viewsJSON format in Localdate field
Personal have the record sequinte being returned by a query using SpringData: page = grupoService.findByNomeStartingWithOrderByNomeAsc(2, pageable); If I run the following code:…
-
0
votes2
answers407
viewsSort objects in json file (Java)
I have the following JSON file: {"idAluno":1,"nomeAluno":"Teste","listaDeTurmas":[1,2,3,4]} {"idAluno":4,"nomeAluno":"Teste","listaDeTurmas":[1,2,3,4]}…
-
0
votes1
answer134
viewsGson does not work
I have a WCF service that returns a Json to be consumed in an Android App, as you can see in the link http://wssmartctrgtr.azurewebsites.net/WsSmart.svc/veiculo/201 However, Gson is not working on…
-
0
votes1
answer693
viewsSerializing and deserializing attributes with names different from Json fields
I’m having the need to serialize and deserialize an attribute that your Json reference has a different name. For example, in the Json I’m receiving there is a field text and would like the value of…