gson

Gson failure to conver symbols

China☆狼群 提交于 2019-12-13 02:26:41
问题 I am using the Gson function toJson for the = , > and < operators, and in the final string they are interpreted as \u003e . Is there a special feature I need to add or take care of? 回答1: You should disable HTML escaping , here is a sample that illustrates it: Gson gson1 = new Gson(); String s1 = gson1.toJson("<>"); Gson gson2 = new GsonBuilder().disableHtmlEscaping().create(); String s2 = gson2.toJson("<>"); s1: "\u003c\u003e" s2: "<>" 来源: https://stackoverflow.com/questions/17092044/gson

how to get JSON representation of Java Objects in JAX-RS layer in java EE 7?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:23:22
问题 We are currently using Java EE 5 and we do something like the following for turning POJO into JSON before sending the response. @GET @Path("/books") @Produces(MediaType.APPLICATION_JSON) public Response getBooks() { List<Book> listOfBooks = getMiscService().getbooks(); String response = "{\"books\":" + gson.toJson(listOfBooks) + "}"; return Response.status(Response.Status.OK).entity(response).build(); } we are using gson API of google. Now that we are restructuring the code to Java EE 7 API

How to use OpenFeign to get a pojo array?

孤街醉人 提交于 2019-12-13 02:17:11
问题 I’m trying to use a OpenFeign client to hit an API, get some JSON, and convert it to a POJO array. Previously I was simply getting a string of JSON and using Gson to convert it to the array like so FeignInterface { String get(Request req); } String json = feignClient.get(request); POJO[] pojoArray = new Gson().fromJson(json, POJO[].class); This was working. I would like to eliminate the extra step and have feign auto decode the JSON and return a POJO directly though, so I am trying this

Parse jsonObject when field names are unknowm

最后都变了- 提交于 2019-12-13 02:01:23
问题 I'm trying to extract some data from a JsonObject. The problem is that the fields that come inside that json have unpredictable names. How can I extract that information having this weird field names? Here is an example: "myObject":{ "216cfa89a2de57554b36b177f0bfbb05":{ }, "0cf9182b5ceba2cb64174141a13e647d":{ }, "eb1d1b19e117ba1387a798d9194b4660":{ }, "157b52871e8e560c7ec0be111ef02363":{ }, "4db69dd3a8ae8e0089bd2959ab0c5f86":{ }, } I'm using gson, where we have the method getAsJsonObject, but

JsonArray as empty string parsing issue with retrofit

一世执手 提交于 2019-12-13 01:26:15
问题 I have a json in which 1 key is coming as jsonArray if it has data otherwise it is coming as empty string. It is giving error while parsing in gson with retrofit. "section": "Technology", "subsection": "", "title": "Depiction of Amazon Stirs a Debate About Work Culture", "abstract": "Details of working conditions at Amazon led to a response from employees, relatives and friends.", "url": "http://www.nytimes.com/2015/08/19/technology/amazon-workplace-reactions-comments.html", "byline": "By THE

Gson make firebase-like json from objects

社会主义新天地 提交于 2019-12-13 01:05:01
问题 In the past a manually created as list of data, which was stored locally in a database. Now I would like to parse those data and put them through import json option into firebase dbs, but what I get doesn't look like firebase generated json. What I get is: [ { "id":"id_1", "text":"some text" }, { "id":"id_2", "text":"some text2" }, ... ] what I want is something like this: { "id_1": { "text":"some text", "id":"id_1" }, "id_2":{ "text":"some text2", "id":"id_1" }, ... } my Card class class

Extra/dupe members in SOAP response prevents serialization (Axis, Java, Gson)

假装没事ソ 提交于 2019-12-13 00:39:48
问题 I am using Axis to call a SOAP-based web service. I'm then trying to serialize the returned remote object as JSON, using the Google Gson library. The serialization to JSON fails, with Gson complaining that "there are multiple elements with the name __equalsCalc()). When I inspect the returned object in my IDE (Eclipse), I can see that this is true -- the returned object has three members called __equalsCalc() and another three called __hashCode. I know from looking around that these are added

Java - Json deserialize data []

安稳与你 提交于 2019-12-13 00:30:32
问题 I am new to stackoverflow. I am creating an Java application which it will get data from a web server. The data is in json format. Example" [ { "item_name": "Adame", "item_type": "Special", "item": "Chestplate", "item_min_lvl": "50", "enchantment": { "health": "0.3", "dam": "24%", "life": "0.1", "xp": "24%", "loot": "22%" }, "def": "73" }, { "item_name": "Sticks'", "item_type": "Unique", "item": "Stick", "item_min_lvl": "4", "enchantment": { "health": "0.6", "mana": "1", "dam": "12%", "life":

Create JSON using GSON with a colon as part of a field's name

你离开我真会死。 提交于 2019-12-12 21:51:23
问题 I've created a set of classes (pojos) that need to be transformed into json. because i have a constraint that json field names adhere to a certain format, i've settled on gson as my library of choice, as it allows for annotations of field names. so, i have json field names like asset_type , preview_image_thumbnail , etc. along with that, any metadata fields must have the format, metadata:<metadata-field-name> . so, what this comes down to is that my metadata:tags and metadata:site annotations

Gson serializing Spring beans

喜你入骨 提交于 2019-12-12 20:41:25
问题 I am using Gson 1.6 and Spring Framework 3.0 for a Java web app on WebSphere 6.1. I have some Spring beans for which the actual instance is a CGLIB proxy. When I attempt to serialize these beans via Gson, the non-primitive properties of the class are not serialized. Instead I get something like: { "CGLIB$BOUND":true, "CGLIB$CONSTRUCTED":true, "booleanProperty":true, "anotherBooleanProperty":true, } where I was expecting something more like { "stringProperty":"stringValue"