gson

Convert ArrayList with Gson to String

你离开我真会死。 提交于 2020-05-12 15:26:11
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I

Gson calls returns empty objects over multiple classes

*爱你&永不变心* 提交于 2020-05-08 18:48:07
问题 I'm trying to serialize to serialize the json string I have included below. { "mood": { "is_featured": true, "description": null, "title": "2014 ", "ordering": null, "is_recently_modified": true, "is_test": false, "tracks": [ { "album": { "release_date": "2014-11-06", "id": 359778, "name": "Amansız Gücenik" }, "name": "Hırpalandı Mayıs", "artist": { "id": 491169, "name": "Ceylan Ertem" }, "duration": 227, "isrc": "TRA161400207", "id": 3903997 }, { "album": { "release_date": "2013-08-05", "id"

Android接入GooglePay

这一生的挚爱 提交于 2020-05-08 08:16:37
准备工作 1、配置好手机的环境(一般是googlePay商城和googlePay服务,必须注册一个账号登录) 2、VPN 3、申请一个googlePay的开发者账号把一些基础信息填好,配好商品D(注:商品ID只能用一次,一但注册好删除后,就无法再次注册商品ID) 4、上传一个包体获得publicKey(代码里面需要) 代码工作 1、准备好androidStudio 2、从他官网的样品中找到aidl这个文件夹存放至Main里面 3、在AndroidManifest中添加权限 < uses-permission android:name ="com.android.vending.BILLING" /> 4、初始化googlePay       String base64EncodedPublicKey ="xxxxxx" ; mHelper = new IabHelper( this , base64EncodedPublicKey); mHelper.enableDebugLogging( true ); mHelper.startSetup( new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { Log.d(TAG, "Setup

Android开发 retrofit入门讲解

我怕爱的太早我们不能终老 提交于 2020-05-05 18:02:18
前言    retrofit基于okhttp封装的网络请求框架,网络请求的工作本质上是 OkHttp 完成,而 retrofit 仅负责网络请求接口的封装.如果你不了解OKhttp建议你还是先了解它在来学习使用retrofit,传送门: Android 开发 框架系列 OkHttp使用详解   Retrofit优势,就是简洁易用,解耦,扩展性强,可搭配多种Json解析框架(例如Gson),另外还支持RxJava. 但是,这篇博客不讲解RxJava配合使用的部分,与RxJava的配合使用将在另外一篇博客中讲解.   另外 retrofit 已经是封装的非常好了,已经最大程度上的匹配各种使用情况,所以不建议多此一举的再次 封装 retrofit(最多封装 retrofit 的单例) . 再次封装不会看起来很帅也不会让你很牛逼. 只会让你看起来更蠢.把已经很拓展很解耦的实现全部破坏. Github地址    https://github.com/square/retrofit 依赖    如果你不需要使用RxJava模式,那么你只需要依赖下面2个: implementation ' com.squareup.retrofit2:retrofit:2.6.2 ' implementation ' com.squareup.retrofit2:converter-gson:2.4.0 '  

Spring-Cloud-Gateway 从升级到放弃

白昼怎懂夜的黑 提交于 2020-05-04 10:55:11
1 为什么要升级为spring-cloud-gateway? Spring Cloud Gateway features: Built on Spring Framework 5, Project Reactor and Spring Boot 2.0 Able to match routes on any request attribute. Predicates and filters are specific to routes. Hystrix Circuit Breaker integration. Spring Cloud DiscoveryClient integration Easy to write Predicates and Filters Request Rate Limiting Path Rewriting 这是官方说的,spring gateway相对spring zuul要新很多,应用也更加自由,开发体验更好。但是我在测试中发现,spring-cloud-gateway相对于zuul来说,更加出众的还是其性能,当然最后让我放弃的也是因为这一点。 网上的朋友也有做一些gateway和zuul的性能比较,大多的结论也是gateway要优于zuul,同时也更加稳定。 但是我们不能轻信,所以我也做了测试,这部分测试内容若不感兴趣可以跳过,zuul就不测试了。

测试报告 alpha

落爺英雄遲暮 提交于 2020-05-04 08:34:50
测试报告 遇到的bug 遇到了线程安全的bug,bug的原因是必须在调用api之前先获取到token,而获取token和调用api都需要新开一个线程,解决方法为通过加锁来解决线程安全问题 遇到了页面的适配问题,在不同的手机上显示的页面差距非常大,解决方法为替换为根据不同屏幕自动调整的relativelayout布局. 动态下滑刷新导致的显示异常bug,解决方法:下滑刷新后清空动态列表 动态推荐、关注、我的、发布来回切换时页面变空白,解决方法:重写fragment的destroy方法 获取到了返回的gson数据,但解析时gson为空. 原因:OnCreatView方法在Handler前执行,将解析部分代码放在Handler内即可 分页获取信息时如果列表数大于100则点击时会崩溃. 原因:设置点击的监听器位置不对,放在第二个Handler下即可 xml文件内空间无法重叠放置. 解决方法: 加一层fragmentlayout即可 点击我的作业,如果我的班级中没有作业,会闪退(在加载列表时判断,若为空则不设置数据) 在我的收藏中点进一个内容返回后会多出一些重复的数据(在onresume方法中不设置UI) 退出程序后本地登录退出但网站的登录端没有退出(在加载网页登录api时先清除本地的web缓存以及cookie) 在本地的ui界面和手机上看的不一样

Java解析JSON的四种方式

断了今生、忘了曾经 提交于 2020-05-02 02:16:19
一、什么是JSON JSON是一种轻量级的数据交换格式,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于阅读和编写,同时也易于解析和生成,并有效地提升网络传输效率。 二、JSON 语法 (1)数据在名称/值对中 (2)数据由逗号分隔 (3)大括号保存对象 (4)中括号保存数组 三、Java中JSON的生成与解析的四种方式(简单的Demo): 一个实体类:用于与JSON数据进行相互转换 public class Person { private String name; private String sex; private int age; public Person(String name, String sex, int age) { this.name = name; this.sex = sex; this.age = age; } public String getName() { return name; } public String getSex() { return sex; } public int getAge() { return age; } @Override public String toString() { return "Person{name='" + name + '\''

Json字符串与Object对象相互转换的几种方式

南笙酒味 提交于 2020-05-01 16:08:12
Json-Lib、Org.Json、Jackson、Gson、FastJson五种方式转换json类型 只列举了最省事的方式。不涉及复制情况和速度。 测试用例,一个User类,属性name,age,location。重写toString()。 public class User { private String name; private Integer age; private String location; public User() { } public User(String name) { this.name = name; } public User(String name, Integer age) { this.name = name; this.age = age; } public User(String name, Integer age, String location) { this.name = name; this.age = age; this.location = location; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return

008-Spring Boot @EnableAutoConfiguration深入分析、内部如何使用EnableAutoConfiguration

喜欢而已 提交于 2020-05-01 05:34:45
一、EnableAutoConfiguration 1、EnableAutoConfiguration原理 springboot程序入口使用注解@SpringBootApplication,SpringBootApplication注解的定义如下 @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter. class ), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter. class ) }) 头部有三个注解, @SpringBootConfiguration:表示是一个配置类 @ComponentScan:自动扫描, @EnableAutoConfiguration: 作用:从classpath中搜索所有META-INF/spring.factories配置文件,然后将其中org.springframework.boot.autoconfigure.EnableAutoConfiguration 的key对应的配置项加载到容器中。 只有spring

Deserialize date attribute of json into LocalDate

可紊 提交于 2020-04-29 12:50:51
问题 I am trying to de-serialize date attribute in json of format "2018-05-27" using Gson. I want date to be in LocalDate format after de-serialization. For json input : { "id" : 1, "name" : "test", "startDate" : "2018-01-01", "endDate" : "2018-01-05", } I am getting error for startDate and endDate : java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING 回答1: The way we can do this is : private static final Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new