Skip to content
Advertisement

Tag: json

How can i extract ” ” “from json register in java

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

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

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

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 :

Advertisement