gson

Gson equivalent in Objective-C

萝らか妹 提交于 2019-12-20 11:37:20
问题 Is there any equivalent to gson in Objective-C? Thanks. 回答1: DCKeyValueObjectMapping https://github.com/dchohfi/KeyValueObjectMapping is not a JSON parser but an object-json mapper to inject NSObject properties from NSDictionary/NSArray. 回答2: I recently used Mantle which works great and is very similar to GSON (which is use for android projects) https://github.com/Mantle/Mantle 回答3: OCMapper is very similar to Gson and easy to use https://github.com/aryaxt/OCMapper Json { "firstName" :

GSON not calling my TypeAdapter for a type which is an interface

感情迁移 提交于 2019-12-20 11:03:53
问题 GSON appears to be doing some kind of trick where it looks at the internal fields of my JavaBeans instead of using the publically-accessible property information. Unfortunately this won't fly for us because our magically-created beans are full of private fields which I don't want it to store off. @Test public void testJson() throws Exception { Player player = new MagicPlayer(); //BeanUtils.createDefault(Player.class); player.setName("Alice"); Gson gson = new GsonBuilder() .registerTypeAdapter

Convert ForeignCollection to ArrayList - ORMLite, Gson and Android

时光怂恿深爱的人放手 提交于 2019-12-20 09:14:35
问题 I apologize if I'm not super clear with my explanation but I'll add to and edit this question for clarity if requested. I am developing an Android app which receives data through an external API and stores data locally using ORMLite. Prior to storing data locally and using ORMLite I had models which retrieved JSON from the server and parsed it via: Gson gson = new Gson(); String result = ApiClient.httpPost("/user_route"); User user = gson.fromJson(result, User.class); The User class was

Convert ForeignCollection to ArrayList - ORMLite, Gson and Android

六月ゝ 毕业季﹏ 提交于 2019-12-20 09:14:00
问题 I apologize if I'm not super clear with my explanation but I'll add to and edit this question for clarity if requested. I am developing an Android app which receives data through an external API and stores data locally using ORMLite. Prior to storing data locally and using ORMLite I had models which retrieved JSON from the server and parsed it via: Gson gson = new Gson(); String result = ApiClient.httpPost("/user_route"); User user = gson.fromJson(result, User.class); The User class was

Spring MVC mapping view for Google-GSON?

醉酒当歌 提交于 2019-12-20 09:03:55
问题 Does anyone know if there is a Spring MVC mapping view for Gson? I'm looking for something similar to org.springframework.web.servlet.view.json.MappingJacksonJsonView. Ideally it would take my ModelMap and render it as JSON, respecting my renderedAttributes set in the ContentNegotiatingViewResolver declaration We plan to use Gson extensively in the application as it seems safer and better than Jackson. That said, we're getting hung up by the need to have two different JSON libraries in order

Json parsing with Gson with data and arrays

試著忘記壹切 提交于 2019-12-20 07:40:32
问题 i am new to web services and i am using gson library for the first time . I am able to parse certain simple json string but i am stuck here . This is my response {"message":"Action completed successfully.","results":3,"action":"param","data":[{"title":"test1","id":2,"completeCount":0},{"title":"test2","id":3,"completeCount":0},{"title":"test2","id":3,"completeCount":0}],"success":true} This is how i am trying to parse it Gson gson = new Gson(); Chracter character = gson.fromJson

Convert json string to list or map [duplicate]

时间秒杀一切 提交于 2019-12-20 07:23:35
问题 This question already has answers here : Converting JSON data to Java object (12 answers) Closed 5 years ago . I get a json string in server side as follow [ {"projectFileId":"8547", "projectId":"8235", "fileName":"1", "application":"Excel", "complexity":"NORMAL", "pageCount":"2", "targetLanguages":" ar-SA", "Id":"8547" }, {"projectFileId":"8450", "projectId":"8235", "fileName":"Capacity Calculator.pptx", "application":"Powerpoint", "complexity":"NORMAL", "pageCount":"100", "targetLanguages":

How to lowercase the JsonElement value in the custom deserializer Gson?

我怕爱的太早我们不能终老 提交于 2019-12-20 07:17:03
问题 I have a custom deserializer for my class as shown below: private class HolderDeserializer implements JsonDeserializer<Holder> { @Override public Holder deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { Type mapType = new TypeToken<Map<String, String>>() {}.getType(); // in the below data map, I want value to be stored in lowercase // how can I do that? Map<String, String> data = context.deserialize(json, mapType); return new Holder(data)

GSON False uppercase

◇◆丶佛笑我妖孽 提交于 2019-12-20 07:15:11
问题 Is there a way to get GSON to recognise "False" as a boolean? e.g. gson.fromJson("False",Boolean.class) 回答1: Yes, you can provide your own deserializer and do whatever you wish: public class JsonBooleanDeserializer implements JsonDeserializer<Boolean>{ @Override public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { String value = json.getAsJsonPrimitive().getAsString(); return value.toLowerCase().equals("true"); }

how to expose class names when serializing with Gson

旧时模样 提交于 2019-12-20 06:21:43
问题 My scenario is very complicated but here's a summary: I'm trying to understand source of a compiler -- and to understand what each AST node represents, I'm generating JSON serializations of ASTs of different programs and later inspect the visualized JSON output. It works great except one problem is that in Gson generated JSON data class names isn't mentioned, so it still doesn't help much. Is there a way to add class names to Gson output without much effort? (without adding some method to