gson

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ on generate APK

ぐ巨炮叔叔 提交于 2020-07-06 09:32:28
问题 My project is run on AVD properly. but when i try to generate signed APK, gradle get this error: FAILURE: Build failed with an exception. * What went wrong: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ > Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more

Gson.toJsonTree(intValue) throws Null pointer exception when trying to pass Integer parameter value

若如初见. 提交于 2020-06-29 04:15:19
问题 We are automating rest APIs using Rest Assured. During this process, trying to have a re-usable method created to pass different JSON nodes with different values. Interger variable created: Integer amt = 50; Method created: public void replaceValues_gson(String mainNode, String childNode, Integer amt) { if(amt != null){ jsonObjectNew.getAsJsonObject("mainNode").add("childNode", gson.toJsonTree(amt)); } //here 'amt' throws an error as java.lang.NullPointerException; Also the amt it shows as 9

How to convert a map to Json string in kotlin?

霸气de小男生 提交于 2020-06-28 03:43:14
问题 I have a mutableMap, val invoiceAdditionalAttribute = mutableMapOf<String, Any?>() invoiceAdditionalAttribute.put("clinetId",12345) invoiceAdditionalAttribute.put("clientName", "digital") invoiceAdditionalAttribute.put("payload", "xyz") I want to convert it into json string the output should be, "{\"clinetId\"=\"12345\", \"clientName\"=\"digital\", \"payload\"=\"xyz\"}" Currently, I am using Gson library, val json = gson.toJson(invoiceAdditionalAttribute) and the output is {"clinetId":12345,

Gson.fromJson does not handle a bad response

与世无争的帅哥 提交于 2020-06-27 17:19:12
问题 I have some code in an Android app where i call a web service and get a json representation of an object back. If successful, it will be a User object. If there is some error, it will be a RestfulStatusResponse object. I was expecting to get a JsonSyntaxException whenever the response is not a Json string representing a User object, but this does not seem to be the case. Can someone explain why? I created this little test code that illustrates it. The String in the fromJson method call is NOT

Correct Date format to use for GsonBuilder Date Format

心不动则不痛 提交于 2020-06-27 16:21:23
问题 My client sends me a date in "2019-11-22T16:16:31.0065786+00:00" format. I am getting the following error: java.text.ParseException: Unparseable date: "2019-11-22T16:16:31.0065786+00:00" The date format that I am using is: new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ") .create(); Please let me know which format to use. 回答1: This format can be handled by DateTimeFormatter.ISO_ZONED_DATE_TIME instance of DateTimeFormatter . It is a part of Java Time package which was released

java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to pojo.class

丶灬走出姿态 提交于 2020-06-17 15:50:19
问题 Getting java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to pojo.class while serializing Generic type.Kindly assist. This is the code written for Json fileReader class. public class ReadJsonFile<T> { private static final Object ReadJsonFile = null; public static void main (String[] args) { ReadJsonFile read = new ReadJsonFile(); read.getjsondata("src/test/resource/testdataresource/addplacerequest.json", Addbook.class); } public List<T> getjsondata(String

Gson issue:- Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 [duplicate]

六月ゝ 毕业季﹏ 提交于 2020-06-17 03:22:14
问题 This question already has answers here : Why does Gson fromJson throw a JsonSyntaxException: Expected BEGIN_OBJECT but was BEGIN_ARRAY? (2 answers) Closed 2 years ago . I am bit new to Gson, I have a json in following format:- { "schedulerName" : "Commodities-ETP_Trade_Entry-FO_TCP_OAS_ALSWP-COM_SLS_BZ", "startRequestDate" : "29-06-2017 23:39:54.910", "activeTestCasesCount" : 7, "statusMap" : { "Assigned" : 2, "In execution" : 1, "Pending" : 4 }, "subTaskCount" : 12, "subTasks" : [ {

Gson issue:- Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 [duplicate]

别来无恙 提交于 2020-06-17 03:22:10
问题 This question already has answers here : Why does Gson fromJson throw a JsonSyntaxException: Expected BEGIN_OBJECT but was BEGIN_ARRAY? (2 answers) Closed 2 years ago . I am bit new to Gson, I have a json in following format:- { "schedulerName" : "Commodities-ETP_Trade_Entry-FO_TCP_OAS_ALSWP-COM_SLS_BZ", "startRequestDate" : "29-06-2017 23:39:54.910", "activeTestCasesCount" : 7, "statusMap" : { "Assigned" : 2, "In execution" : 1, "Pending" : 4 }, "subTaskCount" : 12, "subTasks" : [ {

Kotlin using Gson to deserialize local json file

落爺英雄遲暮 提交于 2020-06-17 00:08:57
问题 I want to deserialize a local json file using Gson to create a recyclerview. However I get an IllegalStateException on below line. val homeFeed = gson.fromJson(json, HomeFeed::class.java) My json file is saved under an assets folder and believe the program reads the data fine but somehow cannot convert it into my HomeFeed model object. Error below: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

Kotlin using Gson to deserialize local json file

雨燕双飞 提交于 2020-06-17 00:07:48
问题 I want to deserialize a local json file using Gson to create a recyclerview. However I get an IllegalStateException on below line. val homeFeed = gson.fromJson(json, HomeFeed::class.java) My json file is saved under an assets folder and believe the program reads the data fine but somehow cannot convert it into my HomeFeed model object. Error below: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $