gson

java gson replace password value while serialization

会有一股神秘感。 提交于 2019-12-11 05:33:58
问题 How can I replace the value of a password field with XXX while de-serializing an object with Gson? I found this post: Gson: How to exclude specific fields from Serialization without annotations that basically skips the field. This would be an option, but I still would prefer to replace the value with XXX I also tried this: GsonBuilder builder = new GsonBuilder().setPrettyPrinting(); builder.registerTypeAdapter(String.class, new JsonSerializer<String>(){ @Override public JsonElement serialize

Gson help with parse array - works without array but won't with array

隐身守侯 提交于 2019-12-11 05:29:49
问题 Can somebody help me with Gson parser. When I remove change from JSON and Result it works fine but with change it throws JsonParseException-Parse failed. Result[] response = gson.fromJson(fileData.toString(), Result[].class); I have classes like this public class Result { public String start_time; public String end_time; public change[] change; } and public class change { public String id; public String name; } and Json string like [ { "start_time": "8:00", "end_time": "10:00", "change": [ {

GSON : How to convert Object (which itself contains JSON) to JSON

南笙酒味 提交于 2019-12-11 05:23:51
问题 I have a different use case where fields in POJO itself stores JSON data, basically grouping of all data. Now i want the complete JSON generated from above POJO. At present i am using this method private static Gson gson = new Gson(); public static String convertObjectToJSON(Object object) throws Exception { String jsonResponse = gson.toJson(object); return jsonResponse; } But getting output with escape characters around double quotes like below { \"_id\" : 234242, \"name\" : \"carlos\"} I

Print json string to html table

偶尔善良 提交于 2019-12-11 05:04:33
问题 I have a very complex JSON string, which is been created by GsonBuilder (in xxx.java) Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); String message = gson.toJson(output); out.println(message); and it look like this: { "status": "error", "number of record loaded": [ { "bid.csv": 24 }, { "course.csv": 12 }, { "course_completed.csv": 0 }, { "prerequisites.csv": 1 }, { "section.csv": 14 }, { "student.csv": 11 } ], "errorList": [ { "file": "student.csv", "line":

How to get value as java.lang.Object from Gson?

我怕爱的太早我们不能终老 提交于 2019-12-11 04:59:22
问题 I have to fetch value from list of com.google.gson.JsonPrimitive and put it in List<java.lang.Object> . I don't know actual type of objects. Later on some other API will do instanceOf check to get proper data type. But JsonPrimitive class above does not return object. I can call isNumber , but that returns a LazilyParsedNumber . Which does not provide isInt etc methods, or access to object so I can call isInstance on it. EDIT: I have done, getAsDouble . that should work for all except

JSON parsing using Gson

戏子无情 提交于 2019-12-11 04:46:40
问题 I am trying to parse a JSON object using GSON. My JSON is : { "truncate": [ { "lower": 20, "upper": 40, "delimiter": " ", "scope": ["$title"] }, { "lower": 30, "upper": 65, "delimiter": " " } ] } I have defined my 2 classes like: public class TruncateObj { private List<TruncateObjectChild> objChild; // getter and setter } and public class TruncateObjectChild { private int lower; private int upper; private String delimiter; private List<String> scope; // getters and setters } My Parsing

How to get variable's value from Gson

半城伤御伤魂 提交于 2019-12-11 04:36:42
问题 First, im a begiiner in GSON so please bear with me. I have a set of classes with this structure : class Response Data data; class Data List<Item> items; class Item String id; String title; Private Player; class Player String mobile; Im using those class to retrieve the JSON with GSON library. I successfully retrieve the JSON data with this code : Gson gson = new Gson(); Response myResponse = gson.fromJson(inputStreamReader, Response.class); When i debug the code, i can see the Item class

Java Parse Json with array with different object types (Gson or Jackson or etc.)

£可爱£侵袭症+ 提交于 2019-12-11 04:31:44
问题 { "response": { "data": { "333": [ { "id": "69238", "code": "545" }, { "id": "69239", "code": "545", "marked": "123" } ], "544": [ { "id": "69906", "code": "544", "marked": "123" }, { "id": "69907", "code": "544" } ], "890": [ { "id": "69238", "code": "545", "marked": "123" }, { "id": "69239", "code": "545" } ] } } } I have this JSON data as a response and try to mapping. Unfortunately I can't. The first reason is index of objects are changeable. For example one index 890 and other one is 544

How do I use Google's Gson to get a certain value from a JSON response?

一世执手 提交于 2019-12-11 04:28:57
问题 I am currently trying to parse through a the front page of Reddit using their cool website feature in which you can add /.json to any site to get the json of the page. So the url I am using is www.reddit.com/.json. I want to get the subreddit of the first post by parsing through their json. How would I do this? I did some research and found the google gson api but I have no idea how to use it and their documentation does not really help me. Here is my code so far, I have the Json in a string:

How to parse Dynamic lists with Gson annotations?

谁说胖子不能爱 提交于 2019-12-11 04:08:25
问题 I am using Retrofit and Gson to query an API, however I have never come across a JSON response like it. The Response: { Response: { "Black":[ {"id":"123","code":"RX766"}, {"id":"324","code":"RT344"}], "Green":[ {"id":"3532","code":"RT983"}, {"id":"242","code":"RL982"}], "Blue":[ {"id":"453","code":"RY676"}, {"id":"134","code":"R67HJH"}] } } The problem is the list elements id eg "black" is dynamic, so I a have no idea what they will be. So far I have created a class for the inner type; class