fastjson

java +testNG 接口测试框架搭建------连接数据库(二)

我的未来我决定 提交于 2020-04-23 04:40:51
在编写的测试脚本中导入连接数据的包: import com.alibaba.fastjson.JSONObject; import com.github.yongchristophertang.database.annotations.SqlDB;//注入数据库包 import com.github.yongchristophertang.database.testng.TestNGDBInjectionModuleFactory; import com.github.yongchristophertang.engine.java.ProxyFactories; import com.google.inject.Inject; import com.qiming.qqzw.resource.api.oversea.IHanyuOverSeaSceneService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context

Springboot2 Tests

非 Y 不嫁゛ 提交于 2020-04-22 01:50:56
import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @RunWith(SpringRunner.class)

(JAVA)支付宝小程序登录相关(authToken获取用户唯一userId、encryptedData解密手机号)

◇◆丶佛笑我妖孽 提交于 2020-04-21 04:04:18
前言: 最近公司做一个支付宝小程序项目,用支付宝userId做唯一用户id,后台encryptedData解密出用户支付宝绑定的手机号信息,其中 参数:authToken和encryptedData均为前端传入,需要和前端协调开发。 正文开始: 贴代码: 1.authtoken获取userId 前端文档 后端文档 public String findUserId(String authCode) throws AdminException, AlipayApiException { AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.url, AlipayConfig.app_id, AlipayConfig.private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.public_key, AlipayConfig.signtype); AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); request.setGrantType("authorization_code"); request.setCode(authCode);

java 泛型T的使用

。_饼干妹妹 提交于 2020-04-20 20:49:42
1.设计背景 ,有common ,web,mgr 三个模块,cmomon做共有模块,web 作为app 的组件,mgr作为后管,在common模块 发起调用接口调用,但是common 模块不能引入web模块的bean 。为了使用面向对象编程,可以把web组件的bean 作为一个属性,传入到common组件的Bean 中 代码如下: 1.泛型的抽象类 package com.qimh.springbootfiledemo.generic; public abstract class GeneratorAbstractor<T> { protected T param; public T getParam() { return param; } public void setParam(T param) { this.param = param; } } 2.实现类 package com.qimh.springbootfiledemo.generic; public class PersonCreator extends GeneratorAbstractor<Person> { } 3.web组件的bean package com.qimh.springbootfiledemo.generic; public class Person { private Integer age;

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

一世执手 提交于 2020-04-17 02:21:53
【推荐阅读】微服务还能火多久?>>> 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

SpringCloud : 多个 @FeignClient 注解 value 设置为同一个应用的解决方案

帅比萌擦擦* 提交于 2020-04-17 02:12:06
【推荐阅读】微服务还能火多久?>>> Feign 版本10.1.0 Spring 版本 5.1.5.RELEASE SpringBoot 版本 2.1.5.RELEASE SpringCloud 版本 2.1.1.RELEASE 在微服务架构中,当我们需要进行服务间调用时可以选择feign组件, 现在遇到的问题是: 当同一个服务,声明多个feign实例时,启动时直接报错。 解决办法, 通过 Feign.builder() 手动生成代理类。 1.定义接口: public interface AbcClient{ @ResponseBody @PostMapping( "/abc" ) JSONObject doSomething(@RequestBody Req request); } public interface DefClient{ @ResponseBody @PostMapping( "/def" ) JSONObject doSomething(@RequestBody Req request); } 2.配置接口代理 import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support

用fastjson反序列化时的一个需要注意的地方

时光毁灭记忆、已成空白 提交于 2020-04-12 15:35:35
问题描述: fastjson反序列化时现解析不正确的问题,expiretime属性值不正确。 问题分析: 当ValidateCode有两个构造函数,且先后位置如图时,fastjson反序列化时,expiretime是不正确的。两个构造函数互换位置后可以正常反序列化。 加入一个无参的默认构造函数(这个构造函数的位置不重要)也可以解决问题。 fastjson的相关源码:com.alibaba.fastjson.util.JavaBeanInfo的build方法和com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer的deserialze方法。 主要关注JavaBeanInfo类中fields和creatorConstructor两个属性的值,基本可以了解为什么会产生上面的问题。 结论: 用fastjson进行反序列化时,对应的javabean需要有默认的构造函数(即按照javabean的规范来)。 来源: oschina 链接: https://my.oschina.net/u/999023/blog/1785611

fastjson生成和解析json数据,序列化和反序列化数据

别说谁变了你拦得住时间么 提交于 2020-04-02 06:59:22
本文讲解2点: 1. fastjson生成和解析json数据 (举例:4种常用类型:JavaBean,List<JavaBean>,List<String>,List<Map<String,Object>) 2.通过一个android程序测试fastjson的用法。 fastjson简介: Fastjson是一个Java语言编写的高性能功能完善的JSON库。fastjson采用独创的算法,将parse的速度提升到极致,超过所有json库,包括曾经号称最快的jackson。并且还超越了google的二进制协议protocol buf。Fastjson完全支持 http://json.org 的标准,也是官方网站收录的参考实现之一。支持各种JDK类型。包括基本类型、JavaBean、Collection、Map、Enum、泛型等。支持JDK 5、JDK 6、Android、阿里云手机等环境。 一. fastjson生成json字符串(JavaBean,List<JavaBean>,List<String>,List<Map<String,Object>) String jsonStrng = JSON.toJSONString(object); 二. fastjson 解析json字符串为四种类型 1. JavaBean Person person = JSON.parseObject

java基础 ---fastjson

馋奶兔 提交于 2020-03-27 07:26:58
fastjson使用案例 一个学生对象如下: 班级对象 public class Grade { private Long id; private String name; private List<Student> users = new ArrayList<Student>(); // 省略 setter、getter public void addStudent(Student student) { users.add(student); } @Override public String toString() { return "Grade{" + "id=" + id + ", name='" + name + '\'' + ", users=" + users + '}'; } } 学生对象 public class Student { private Long id; private String name; // 省略 setter、getter @Override public String toString() { return "Student{" + "id=" + id + ", name='" + name + '\'' + '}'; } } 运行的 Main 函数 public class MainTest { public static void

java序列化与反序列化

烈酒焚心 提交于 2020-03-26 19:11:14
先描述下这里的业务: 我们有一个父类A,多个继承A的AA类、AB类、AC类,多了一些不同的业务字段。 业务分为多个端,如:甲端、乙端,通过kafka来交互数据,数据格式为一个VO,包含多个业务属性以外,还有一个List<A>属性引用类,这里实质内容还是AA、AB、AC类。 甲端封装好对应的参数后,传递给乙端进行解析时。json无法直接转成对应的AA、AB、AC实现类。其中的业务字段会丢失。 这就是疑问的地方??? 这里我们比较了一下fastJson和gson,最后采取gson来解决此问题。 fastJson 是通过注解形式。如: @JSONField(serializeUsing=ToSystemNameSerializer.class) 这里ToSystemNameSerializer.class是我们自定义的转换类,需要实现ObjectSerializer和ObjectDeserializer分别是fastjson的编码器和解码器接口 Gson 是同通过注册TypeAdapter。如: Gson.addTypeAdapter(Type,ToSystemNameSerializer) 然后使用gson来解析json,如果识别到Type类了,则使用我们定义的ToSystemNameSerializer来解析