Questions tagged [gson]

Gson is Google's open-source library for serializing and deserializing Java objects to/from JSON.

Gson is Google's open-source library for serializing and deserializing Java objects to/from JSON.

The Gson project is hosted at and available for download from https://github.com/google/gson and licensed using the Apache License 2.0

Latest release: 2.8.6 released on Oct 4, 2019

Project Links

  • Gson API: Javadocs for the current Gson release
  • Gson guide: This guide contains examples on how to use Gson in your code.
  • Gson Roadmap: Details on upcoming releases

Alternatives

Alternative Java-to-JSON binding solutions with similar APIs include FastJSON, Jackson, and svenson. Yet more Java-to-JSON libraries are listed at json.org.

Performance

The latest performance benchmarks for these and other JSON serialization and deserialization solutions for Java are available at https://github.com/eishay/jvm-serializers/wiki.

9768 questions
3
votes
3 answers

remove backslash from display of string(gson)

I have the list Gson gson = new Gson(); List exampleList = new ArrayList(); exampleList.add("aaa"); exampleList.add("bbb"); exampleList.add("ccc"); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("test",…
user3569530
  • 193
  • 2
  • 4
  • 13
3
votes
1 answer

Getting error in gson deserializing using android Studio

I am working on an application in which I am using android phone contacts in my application.So, for that first of all fetch contact details and store it into ArrayList. After that I serialized that arrayList using gson library and when I deserialize…
3
votes
1 answer

writeObject() and readObject() are not called during serialization

I have a Test class, shown below: package examples; import java.io.IOException; import java.io.Serializable; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; public class Test implements Serializable { private static final…
balazswmann
  • 137
  • 1
  • 1
  • 7
3
votes
3 answers

How to convert the free text into Json String Array in Java using GSON library?

I am having free text available into the file. I am stucked while convert it into the json string array The columns names are variable and can be n number of columns email_from,email_to,DATE_CHANGED samwilliams@gmail.com, mike_haley@gmail.com,…
Angie Russell
  • 87
  • 2
  • 9
3
votes
2 answers

Retrofit 2.0.0 beta2 : expected begin_array but was begin_object

i'm receiving every time this Error : expected begin_array but was begin_object i don't know if i need to add a deserializer or a warrper class to retrofit but i don't know how i can do it in a easy way to fit my api json response for all my project…
Mourad
  • 65
  • 6
3
votes
2 answers

About Turn List to String With GSON

I use gson to take List into String. Like this: Gson gson = new Gson(); String youtubeListStr = gson.toJson(List strList); And then get this by : Gson gson = new Gson(); Type type = new TypeToken>() {}.getType(); List
WhiteBanana
  • 349
  • 4
  • 20
3
votes
1 answer

json: references

I'm using JSON with Gson package for java. I have an object where there are some inner references from object in one field to object in another field. For example: { "loci": [ { "id": "loc1", "length": 10000, "start": 2 }, { "id":…
David B
  • 29,258
  • 50
  • 133
  • 186
3
votes
3 answers

Merging object modifications into a java object (JSON)

I want to modify a java object by passing a json String to my application. The String will not contain all information about the complete, modified object but merely a single member that's meant to be set. class SomeClass { Object var1 =…
birgersp
  • 3,909
  • 8
  • 39
  • 79
3
votes
1 answer

Java Gson java.text.ParseException: Unparseable date

I'm sending a JSON object (A rather big JSON object) to a Java servlet, I then use Gson to convert the JSON to an object. Though when I try and do so I get the following: java.text.ParseException: Unparseable date: "May 1, 2008" I essentially have…
user818700
3
votes
2 answers

GSON: Not calling my Deserializer

I made a Deserializer in my project however this it is not being called I am using Retrofit 2.0 with GSON and this is one my API calls @GET(UrlConstants.GET_EVENT_COMMENTS) …
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
3
votes
1 answer

Custom gson serialization for an abstract class

Maybe I'm running in the wrong direction, but I have a list of elements which I want to read. I have an abstract base class let's call it Person: public abstract class Person { public int id; public String name; } Now I have two possible…
rekire
  • 47,260
  • 30
  • 167
  • 264
3
votes
1 answer

Using Gson for Restlet to convert Post data (Representation) to an Object

I am trying to post a form to a Restlet ServerResource and read it into an object using Gson Restlet Extension. There's no documentation on how to use it and nothing on StackOverflow. What is the correct way of using gson restlet…
ntsh
  • 759
  • 5
  • 19
3
votes
1 answer

Make Gson behavior depth-dependent

Is there a sane way of making Gson handling nested objects differently from those at the top level? Things to be serialized are entities and they all have an id. A nested entity should be replaced by its id (to shorten the output and possibly fight…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
3
votes
1 answer

Error parsing field as object or array

i have the following Json string, which I'm suppose to deserialize. The problem is: since this string comes from a server I can't change it and I need to deserialize as POJO. You can see that the Grafs keys have different values for each subarea.…
Rui Sousa
  • 53
  • 9
3
votes
1 answer

JSON Initial capital key issue with parsing in GSON

I have previously JSON response in REST API like below, Example, {"id":"1234"}. I created an POJO class to set it like below. import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class Example { …
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
1 2 3
99
100