gson

Specified object from JSONObject

…衆ロ難τιáo~ 提交于 2019-12-24 05:53:50
问题 I have JSONObject which contains as shown below and created class Markets contained all fields. I want put JSONObject elements to created object of Markets . Example: Markets markets = new Markets() ,then put elements from JSONObject to markets and I want to be able to get markets.getInstrumentName() . How can I do this ? I try using Gson , like this Markets markets = gson2.fromJson(jsonObject, Markets.class); but there are different types and it is wrong way. JSONObject : { "map": {

proguard for multiple maven module project

自作多情 提交于 2019-12-24 05:05:05
问题 I have a plugin reference to proguard in a multi-module maven project. The functionality of my project is fully tested and works...until I add proguard. Structure of my Project parent-pom -module-a-pom -module-b-pom tester-pom module-b has a dependency on module-a. module-a and module-b are both installed to my local maven repository. tester has dependencies on both module-a and module-b. My proguard.conf file is next to the parent-pom pom.xml file on the file system. I configure proguard in

JavaScript unable to parse string serialized with Gson from Java [duplicate]

女生的网名这么多〃 提交于 2019-12-24 04:52:05
问题 This question already has answers here : How to escape double quotes in JSON (6 answers) Closed 2 years ago . This is not a duplicate of this question as the question here is specifically about representation of JSON strings serialized from Java in literal form in JavaScript (and it's more than double quotes one has to worry about). I am creating in Java a serialized JSON object using Gson which I am subsequently unable to internalize from Javascript using JSON.parse. This occurs when I have

JavaScript unable to parse string serialized with Gson from Java [duplicate]

一个人想着一个人 提交于 2019-12-24 04:51:47
问题 This question already has answers here : How to escape double quotes in JSON (6 answers) Closed 2 years ago . This is not a duplicate of this question as the question here is specifically about representation of JSON strings serialized from Java in literal form in JavaScript (and it's more than double quotes one has to worry about). I am creating in Java a serialized JSON object using Gson which I am subsequently unable to internalize from Javascript using JSON.parse. This occurs when I have

Parsing Retrofit2 result using Gson with different JSON structures

混江龙づ霸主 提交于 2019-12-24 04:26:17
问题 When I call the API, depending on the parameters, the name of the same field in the JSON returned changes. In the example below, in one case the field "user" is named "userA" or "userB". I'm using Gson but I don't want to create an object to parse the root of the JSON as I'm only interested in the list of users and I want my call to return this list only. { "apiVersion":"42" "usersA":[{ "name":"Foo", "lastname":"Bar" ... } ] "otherData":"..." } or { "apiVersion":"42" "usersB":[{ "name":"Foo",

JsonObject add property - maps

大城市里の小女人 提交于 2019-12-24 04:04:15
问题 I have a class called Test with a String id field and a HashMap map like Map<String, String[]> , Map<String, ArrayList<String>> , and Map<String, HashMap> (Here the second HashMap is a <String, Integer> one) I have the following code. JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", test.getId); Like this, I want to add the Map to this. Adding like jsonObject.addProperty("map", String.valueOf(test.getMap())); does not do the work properly as it add "(commas) to beginning

How do I deserialize Json with modifying the structure?

我是研究僧i 提交于 2019-12-24 03:48:07
问题 I have this Json content: { "people":[ { "name":"test1", "sirname":"test2", "details":{ "social_no":1234567, "creadit_card_no":34582342309 } }, { "name":"test3", "sirname":"test4", "details":{ "social_no":12345679, "creadit_card_no":345823423090 } } ] } and according to logic this Json should have 3 POJO classes: A class that will hold the list of People, People object and a Details object. Now my question is, is it possible to deserialize this Json using Jackson or if not possible with

Gson parsing problem with release version - incorrect string is returned

回眸只為那壹抹淺笑 提交于 2019-12-24 03:43:37
问题 Hi i've problem with the library Gson in a release version. In practice, in the release version of my application, using the new Gson().toJson(obj) method an incorrect string is returned. The returned string is missing some field of my object. Is it possible that the release version needs some missing options? Here are some useful information: The obj is an instance of ArrayList<MyClass> I'm using implementation 'com.google.code.gson:gson:2.8.5' I'm using Android Studio 3.5.1 MyClass is build

GSON fails parsing JSON with string space

家住魔仙堡 提交于 2019-12-24 03:29:49
问题 I have the following object: public class ParameterWrapper<T> { private String type; private T value; public ParameterWrapper(String type, T value) { this.type = type; this.value = value; } public String getType() { return type; } public void setType(String type) { this.type = type; } public T getValue() { return value; } public void setValue(T value) { this.value = value; } } I am serializing it into JSON using the Gson library. When value contains a string with no spaces, it works perfectly

Java JSON library that supports DOM-style access

霸气de小男生 提交于 2019-12-24 03:27:55
问题 I'm writing a JSON-style query engine in Java, and it would benefit from the ability to query a JSON document by the DOM path (like you can do in Javascript). I've checked out GSON and Jackson, but neither seem to support this. Anyone know of any alternatives, or other suggestions rather than rolling my own? e.g. //Example JSON document String json = "{ somewhere : {deep : { inside : 123 } }, anarray : [{val=1}] }"; JsonElement root = JsonParser.parse(json); //What I'd like: JsonElement node