Questions tagged [gson]
Gson is Google's open-source library for serializing and deserializing Java objects to/from JSON.
9,710
questions
1
vote
0
answers
14
views
how to serialize groovy traits with gson
I got a class implementing a trait which i want to serialize:
package com.company.project.model.v2
import com.company.project.traits.v2.TOpeningTimes
class Gasstation extends Poi implements ...
0
votes
3
answers
54
views
Deserialise a dynamic JSON into a java object
Is it possible to somehow convert a dynamic JSON object (No fixed schema) into a Java object?
For example, for first time, I can get the following JSON object at runtime:
{
"addressDetails"...
0
votes
0
answers
22
views
GsonBuilder will not be found
enter image description hereHow to resolve this Error?
java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder
I'm trying to build a DSL in Xtext in Eclipse IDE and I install the Gson Jar to class-...
0
votes
1
answer
25
views
How to map JSON object with slashes in field name?
I am self-learned beginner in Java coding so please be understanding.
I am writing REST api app that at some point expects to get such response from server:
[
{
"success": {
...
0
votes
0
answers
30
views
How to save the tree structure of classes in SharedPreferences
I've tried using Json, kotlin serialization, Parcelable, but nothing works.
The code of my class looks like this:
data class Item(
var name: String,
var children: MutableList<Item> = ...
0
votes
2
answers
32
views
Gson java.time.LocalDateTime serialization error
I am trying to serialize a class with google Gson Library.
public class XYZ {
private String name;
private LocalDateTime timeCreated;
}
I getting an error when I try to execute return gson....
0
votes
0
answers
22
views
Gson.toJson(Any) always get {} when using springboot3.0 native image
I'm using Kotlin lang with springboot3.0. The way I package the native package is ./mvnw native:compile -Pnative.
Gson version is 2.10.1
springboot version is 3.0.2
fun doSometing(payload:Any){
...
0
votes
1
answer
29
views
Deserialization of nested JSONs
I have the following JSON string
final String testInputString = "{\"actions\":[{\"actionName\":\"LOGIN\",\"actionAttributes\":{\"emailId\":\"...
-1
votes
1
answer
45
views
Gson issue. My .java file does not accept "import com.google.gson.*;"
I have maven and java installed on my system. When typing "import com.google.gson.Gson;" does not seam to work. See image one or code sample one.
(code sample one)
import com.google.gson....
-2
votes
0
answers
19
views
a problem that use gson to convert json string to a model class with List<T>(ClassCastException)
I have a json,need to convert it to a class.but there is an ClassCastException.
my test code:
fun main() {
sendRequest(object : RespCallBack<MyRespData<PageInfo<MoreAppInfo>>>() {...
1
vote
1
answer
23
views
Parse Json String Reponse (List of Users) and get each individual element in a list (i.e. User). Works for one user, but not for a list of users
I am using this endpoint for testing my parser: https://jsonplaceholder.typicode.com/todos/
Example of Json string response:
{
"userId": 1,
"id": 1,
"title": "...
0
votes
0
answers
14
views
using gson.toJson() for LocalDateTime field makes error Spring Rest Docs?
I got test failed while implementing Spring Rest Docs code.
Status expected:<201> but was:<400>
This is the suspicious part.
BookDto.Post post = new BookDto.Post("미움받을 용기", "...
1
vote
0
answers
17
views
How to insert List<LocalDateTime> in room database?
I am using LocalDateTime from kotlinx-datetime library. Want to insert List<LocalDateTime> in Room database. Typeconverter written using Gson library. But following error showing.
java.lang....
0
votes
0
answers
19
views
Parsing an Okttp Response that starts with " [ {...}, {...}, {...} ] " where the first array has no label / key but seems to be a list [duplicate]
I am making a geography app, where people can look up a list of countries, search for a specific country and get a country's info such as Language, Capital, etc.
My issue is parsing my Okhttp Response....
0
votes
0
answers
11
views
Gson not throw exception for wrong class mapping when using fromString?
Gson not throw exception for wrong class mapping when using fromString?
Supposing I have a data class in Kotlin:
data class VisaFxRate200Response(
@SerializedName("conversionRate")
...
0
votes
0
answers
21
views
Problem: I don't know how to correctly send new data on the screen
I am creating a game in the genre of novel. In order not to create a "million" different screens with different data, I decided to store the entire story of the game in a json file. ...
0
votes
2
answers
64
views
Java GSON not deserializing all fields, even when they are of same type
I have the classes:
public class SentPlayer {
final String uuid;
final String playerName;
final String universeUuid;
/* some get methods and constructors */
}
public class PlayerMsg {
...
0
votes
1
answer
54
views
Gson - How to use gson to deserialize nested objects with changing keys?
An example json I am trying to parse is:
[
{
"id": "123",
"a*": {
"b*": {
"prio": {
...
-1
votes
1
answer
93
views
Gson Date Conversion [closed]
I'm receiving the date in the format from the server is yyyyMMdd HH:mm:ss and I need to convert to the date format yyyy-MMM-dd HH:mm:ss using Gson JsonDeserializer.
Example:
Received date from server:...
2
votes
1
answer
35
views
Getting an error when trying to assign a List<Rank>
I have tried to parse a JSON formatted text from my Web API into an ArrayList of Rank.class, but I have been getting a ClassCastException error with message
Cannot cast com.google.gson.JsonPrimitive ...
0
votes
0
answers
42
views
Junit 5 for Gson used in aem servlet
I have a java pojo class "IdDetails.java" with Getter/Setter methods. I am mapping this pojo in another Servlet using Gson.fromJson . When I am instantiating Gson in Junit5 Test Class it is ...
0
votes
0
answers
42
views
How do we read multiline json string in a text file.?
I have a log file. it has request json string and response json string. both are in there with multilines.
so how do we read json string in there.?
log file sample :-
URL : /saveEmployee
REQUEST ...
0
votes
1
answer
40
views
Extract an array from a Json file to put it in a class object
so these are my classes
public class Fencers{
private String name,nation;
private int id;
public Fencers(String name, String nation,int id) {
this.name = name;
this.nation ...
0
votes
2
answers
33
views
Convert a Json file to a class objects but it's in a weird format
Hello so this is my code:
public class Fencers{
private String name,nation;
private int id;
public Fencers(String name, String nation,int id) {
this.name = name;
this....
0
votes
0
answers
20
views
Json deserialization using Gson explanation
Help me please. I can not understand why deserializaer works on Http responses, but on json string do not work.
The string is {"link":"protocol://main","title":"Test ...
1
vote
2
answers
31
views
how to reformat a json file in java
Okay so this is my code -->
first we have a normal class:
public class Fencers{
private String name,nation;
private int id;
public Fencers(String name, String nation,int id) {
...
0
votes
1
answer
21
views
GSON throwing "Expected BEGIN_ARRAY but was BEGIN_OBJECT"?
The code throwing the exeption:
String inputString = readWithScannerGson("outputGson.txt");
Type outputListType = new TypeToken<ArrayList<CPU>>(){}....
0
votes
0
answers
77
views
error: package com.google.gson does not exist import com.google.gson.Gson;
i downloaded a minecraft mod and im trying to change the code, so i decompiled the mod and changed the code but when i try to compile it in cmd i get this error error: package com.google.gson does not ...
0
votes
0
answers
85
views
Compare Two Large JSON array
I have two directories "A" and "B", each directory contains textfiles containing jsonarray of jsonobjects.
Need to compare jsonobjects in directory a with b and figure out which ...
0
votes
1
answer
27
views
Replace usage of new Gson().fromJson() with com.fasterxml.jackson.databind.ObjectMapper covering all the cases
Currently we are using Gson to convert a JSON String to Map<String, String>. It is required to eliminate use of Gson completely and replace it with ObjectMapper.
Currently if we are to convert ...
0
votes
0
answers
22
views
Parse tree structured json file to POJO class
I have a JSON file that looks like this
{
"deviceNodes": [
{
"header": "Mobiles",
"metadata": "",
"children": [
...
0
votes
1
answer
15
views
How to use GSON streaming to parse JSON with multiple top-level objects?
I've been looking for example Gson streaming API code, and I see a lot of this style:
reader.beginObject();
while (reader.hasNext()) {
switch(reader.peek()) {
...
0
votes
0
answers
14
views
Deserializing with Gson into different POJO types [duplicate]
I have Websocket API, which spews out data in JSON format, and client endpoint reacts on them asynchronously.
Since Jsons are lengthy, I want to work with them in deserialized form. Gson can ...
-1
votes
0
answers
30
views
Parsing string as array of json objects in Kotlin
I have an input as string :
input = "[{"a" :"hello"},{"a" :"world"}]"
I want to cast this as an arraylist of json objects.
End goal is to access via ...
0
votes
1
answer
32
views
JSON conversion does not work as expected
The program stops when it encounters the command new Gson().toJson(emailPOJO);
Simple strings work so probably the problem is the Object emailPOJO, but I searching online I did not find anything ...
0
votes
1
answer
27
views
Error trying to serialize to Json but error does not happen if I don't add cages
[19:44:33 ERROR]: Could not pass event InventoryClickEvent to LuckyWars v1.0.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:...
0
votes
0
answers
19
views
Android (Kotlin): registerTypeAdapter (gson) not calling
Morning. I use gson library 2.9.1, and found a library issue (deserialization fails based on the user's 24-hour preference), more information about this crash is here -> https://github.com/google/...
0
votes
1
answer
34
views
How can GSON be configured to recognize ISO date fields as parse them as Date objects?
This code:
Map<String, Object> map = new HashMap<>();
map.put("now", new Date());
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
...
0
votes
1
answer
22
views
parsing JSON with a lot of similar fields
I have this kind of json response:
"rates": {
"first":1,
"second":2,
"thirds":3,
...
}
i'm using Gson, so my response class looks like this:
Public class ...
0
votes
1
answer
27
views
My retrofit gson deserializer don't see enum
Whenever I'm getting response from the server where JSON looks like that
{"rights":[{"name":"stock_management","right":true}]}
my retrofit uses class ...
3
votes
1
answer
59
views
How to deserialize String to java Instant
I have a a JSON string as :
{
"personId": "person1",
"userId": "user1"
"details": [
{
"homeId": "home1&...
0
votes
1
answer
24
views
Bug using Gson, Serialization and minified
At the beginning the app works fine(Emulator and physical device), but when I create the project and upload the application to the play store, just stop working(Login App).
I found when:
...
0
votes
0
answers
27
views
java.lang.NoClassDefFoundError with Gson using Maven
I'm trying to use the GSON library to parse a JSON file in my Maven project. I've added the following dependency to my pom.xml file:
<dependency>
<groupId>com.google.code.gson</...
0
votes
1
answer
37
views
How to deserialize n-dimensional json array of a given data type in java [closed]
Unable to write a generic code which can deserialize these json (represents tensor data) to java array using libraries like gson, jackson etc
example json1
{
"dim": [1,4],
"type": &...
-1
votes
0
answers
17
views
Parsing json object (String) using gson [duplicate]
I am trying to parse a json object which is in string format using gson.fromJson function.
But I am getting gson.stream.MalformedJsonException exception.
import google.gson.reflect.TypeToken;
import ...
0
votes
1
answer
34
views
Upgrade from gson 2.3 to 2.8.9/2.10.1 failed in deployment -java.io.IOException: invalid constant type: 19
As gson 2.3 is vulnerable ,upgrading to 2.8.9 or any newer versions failed in deployment with the below exception.
org.jboss.deployers.spi.DeploymentException: Error deploying ***: invalid constant ...
0
votes
1
answer
28
views
Skip serializing GSON field in generics based on value
We have the need to distinguish between an optional fields vs. nullable fields (i.e when a field is present, that it could be nullable) when serializing Kotlin data classes to JSON using GSON.
The ...
0
votes
0
answers
62
views
[Guice/ErrorInCustomProvider]: NoSuchMethodError: 'void ConstructorConstructor.<init>(Map)' at GsonModule.provideGson(GsonModule.java:99)
I have a Spring Boot project which uses jClouds and has 2 classes as shown below:
@Configuration
public class S3Config {
@Value("${amazon.s3.access-key}")
private String accessKey;
@...
0
votes
0
answers
26
views
Getting com.google.gson.JsonSyntaxException Dec 29, 2022 16:20:00 (Kotlin)
Morning. Could you help me with this issue, please?
What template for this date format should I use -> Dec 29, 2022 16:20:00
1
vote
2
answers
50
views
How can I create a DTO structure for JSON objects with a variable number of variables?
I'm having trouble converting data from an API to a Java object in Kotlin. For example, if there are two pieces of information in the API, I should make a data class like this:
data class Persons(
...