gson

Second level expand in gson

纵饮孤独 提交于 2020-01-15 09:23:05
问题 I'm using Grails 3.2.2 and org.grails.plugins:views-gradle:1.1.1 and in my section gson I'd like to expand all users and their carnets. I tried: import com.example.sections.Section model { Section section } json g.render(section, [excludes:['archived', 'deleted'], expand:['clients', 'clients.carnets']]){ } but it only expands clients in result json. how can I do that? btw carnets in Client domain class are transient. Is it possible to add transient variables to result gson? If so - how? 来源:

Display JSON data on Android using GSON and Volley

扶醉桌前 提交于 2020-01-15 03:21:29
问题 Hello I'm new to android programming and trying to learn it. I followed this tutorial and it's working fine however I don't know how to display the records in the listview. The PostActivity.java file is from the tutorial is below, package com.kylewbanks.gsonvolleytutorial; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley

Store data into Realm through Retrofit 2

最后都变了- 提交于 2020-01-14 05:07:40
问题 I am new for Realm integration. I am trying to save my retrofit json response into Realm database. But still I am confuse how to complete this task for retrofit 2. I am getting json response and extends RealmObject class as per RealM documents. but still not getting any good way to store my response into realm directly. Dashboard Activity: apiInterface = APIClient.getClient().create(APIInterface.class); final Call<RealmList<ExampleTest>> call = apiInterface.getSurvay(); call.enqueue(new

Android studio project not compiling after updating firebase-perf plugin (Class module-info is missing)

只愿长相守 提交于 2020-01-13 19:28:08
问题 everyone. I'm using gradle version 5.6.2. I updated my android studio project dependencies like this: dependencies { classpath 'com.android.tools.build:gradle:3.5.1' classpath 'com.google.gms:google-services:4.3.2' classpath "com.google.firebase:perf-plugin:1.3.1" } I apply the plugins like this: apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'com.google.gms.google-services' But now when I compile my project this error shows up: Illegal class file: Class module-info is

Parsing JSON with a random field (java)

╄→尐↘猪︶ㄣ 提交于 2020-01-13 13:50:39
问题 I want to convert a JSON file into a CSV file. My JSON file comes from a DataBase stored in Firebase and has an structure like this: { "PATIENT" : { "-LbhwHC7Y6_umc" : { "age" : 31, "name" : "Phoebe" }, "-LbhwTFJ6xjEf" : { "age" : 20, "name" : "Amy" }, "-LbhxUmJ_dwIC" : { "age" : 28, "name" : "Joe" } } } I'm trying to do it with Gson : package Parser; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import com.google.gson.Gson; public class Main { public

Parsing JSON with a random field (java)

牧云@^-^@ 提交于 2020-01-13 13:50:08
问题 I want to convert a JSON file into a CSV file. My JSON file comes from a DataBase stored in Firebase and has an structure like this: { "PATIENT" : { "-LbhwHC7Y6_umc" : { "age" : 31, "name" : "Phoebe" }, "-LbhwTFJ6xjEf" : { "age" : 20, "name" : "Amy" }, "-LbhxUmJ_dwIC" : { "age" : 28, "name" : "Joe" } } } I'm trying to do it with Gson : package Parser; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import com.google.gson.Gson; public class Main { public

Proguard is ruining my cleanliness. Gson and generics

丶灬走出姿态 提交于 2020-01-13 03:12:18
问题 I have a function that loads information from persistence, and I just tell the type it is in a really simple way. The class is called SharedPreferencesHelper.kt so it is a really life problem solver: fun <T> loadList(context: Context, fileName: String, key: String, defValue: ArrayList<T>) : ArrayList<T> { val gson = MyGsonDependency.getInstance() val json = getWithFileName(context, fileName).getString(key, gson.toJson(defValue)) return gson.fromJson(json, object : TypeToken<ArrayList<T>>() {}

Is it possible to deserialize JSON property names with periods as a nested object using GSON?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 02:55:05
问题 This is an example of the kind JSON I'm trying to consume using GSON: { "person": { "name": "Philip" "father.name": "Yancy" } } I was wondering if it were possible to deserialize this JSON into the following structure: public class Person { private String name; private Father father; } public class Father { private String name; } So that: p.name == "Philip" p.father.name == "Yancy" Currently I am using @SerializedName to obtain property names containing a period, e.g.: public class Person {

Android--解析JSON格式数据

扶醉桌前 提交于 2020-01-13 00:36:33
解析 JSON 数据也有很多种方法,可以使用官方提供的 JSONObject,也可以使 用谷歌的开源库 GSON。另外,一些第三方的开源库如 Jackson、FastJSON等也非常不错。 修改 MainActivity 中的代码,如下所示: public class MainActivity extends Activity implements OnClickListener { …… private void sendRequestWithHttpClient() { new Thread(new Runnable() { @Override public void run() { try { HttpClient httpClient = new DefaultHttpClient(); // 指定访问的服务器地址是电脑本机 HttpGet httpGet = new HttpGet("http://10.0.2.2/ get_data.json"); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == 200) { // 请求和响应都成功了 HttpEntity entity = httpResponse

JSON 之GSON 解析

陌路散爱 提交于 2020-01-13 00:35:28
一、 谷歌GSON这个Java类库可以把Java对象转换成JSON,也可以把JSON字符串转换成一个相等的Java对象。Gson支持任意复杂Java对象包括没有源代码的对象。 二、Gson解析Json步骤 A、服务器端将数据转换成json字符串 首先、服务器端项目要导入Gson的jar包到BuiltPath中。( Gson的jar:http://code.google.com/p/google-gson/ 我们还可以下载gson的帮助文档 ) 然后将数据转为json字符串,核心函数是: public static String createJsonString(Object value) { Gson gson = new Gson(); String str = gson.toJson(value); return str; } B、客户端将json字符串转换为相应的javaBean 首先客户端也要导入gson的两个jar包 ,json的jar就不需要导入了( 因为android项目中已经集成了json的jar包所以这里无需导入 ) 1、客户端获取json字符串 public class HttpUtil { public static String getJsonContent(String urlStr) { try {// 获取HttpURLConnection连接对象