I’m working with a java’s library (Gson) to store new Users in a file named “users.json). When i register a new one, my code reads previous data in the file to convert and add with the new data in a List of Users to write the new content to the json file. The problem comes when the previous data are
Tag: json
How to deal with “cannot be cast to class” error – GSON JAVA
i am trying to write my list to jtable in abstract model and then its return to me this error. In my opinion it could be cause by list format? name and amount are in wrong place. This is my full error message: Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap cannot be cast to class Model.Medicine (com.google.gson.internal.LinkedTreeMap and Model.Medicine are
How to deserialise anonymous array of mixed types with Jackson
In my Java program, I am trying to parse data that I get from Strava.com’s API. One of the JSON payloads, I receive from there looks as follows: Basically, four of these entries (altitude, velocity_smooth, distance and time) have the same structure (their data field is an array of doubles (or ints that can be parsed as doubles)), but the
JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
I am sending request to external service which has updatedDate property When I receive the response in my DTO I am trying to format the LocalDateTime property like this But I get error in Postman Answer There are milliseconds in the input string, so your format should be “yyyy-MM-dd’T’HH:mm:ss.SSS” Update: If the millisecond part consists of 1, 2, 3 digits
Conditionally serialise fields in Gson
I have two classes : Player and Match. Player has two fields, playerId and name while Match contains two Player objects and matchId too. When I serialise Player I do want the id and the name to appear in the JSON, however when I serialise Match I get matchId and Player’s non transient fields and their respective values even though
How to store JSON file as a JSON datatype in mysql using Hibernate / Spring boot?
I’ve tried several ways of storing a json file in a database but it ends up creating different columns for each entry. I want to store it as a “json” type in a single column. Is it possible? My json file. users.json It’s a spring-boot application and I’ve the relevant controllers and services. In my domain package. (Address and Company
Sonar “Make transient or serializable” error
I have the following serializable class (implements serializable): However , it seems like this property is causing some problems with serialization : How can I solve this problem ? Also , is there any downside in not making this transient or serializable ? Will I be able to serialize this class fully ? Answer The Map interface does not extend
Parse array JSON Schema with Jackson
I have a JSON Schema defined : It’ll always be a schema which contains firstly items and then it’ll contain properties. In properties can be more arrays or objects found so I want to do that recursively. What i’m trying to achieve is a Map<String, Object> which directly represents the schema. Where I’m getting stuck is the recursive call where
Jackson encode all properties to base64
I have more than one class that I want to serialize using Jackson to generate Json, for example I need to encode all value of the json to base64, so I configure the object mapper like this The problem is it’s only encode the String type as the serializer only accept one type, is there any method to encode all
Serializing a double property as string
Which @JsonXyz annotation do I have to use when I have a bean to be jsonified but serializing a double proeprty as string. An example: I have a bean: And I wan tto have a JSON like: instead of: So, the value 100.0 shall be in quotes. Answer If you are using Jackson you can use @JsonSerialize and ToStringSerializer :