Skip to content

Commit 6f768e4

Browse files
author
Troy
committed
新增 okhttps-fastjson2 模块
1 parent 467746d commit 6f768e4

9 files changed

Lines changed: 121 additions & 25 deletions

File tree

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
package cn.zhxu.okhttps.fastjson;
22

3+
import cn.zhxu.data.fastjson.FastjsonDataConvertor;
34
import cn.zhxu.okhttps.ConvertProvider;
45
import cn.zhxu.okhttps.MsgConvertor;
5-
import cn.zhxu.okhttps.OkHttpsException;
6-
import com.alibaba.fastjson.JSON;
7-
import cn.zhxu.data.fastjson.FastjsonDataConvertor;
8-
import okio.Okio;
9-
10-
import java.io.IOException;
11-
import java.io.InputStream;
12-
import java.lang.reflect.Type;
13-
import java.nio.charset.Charset;
146

157
public class FastjsonMsgConvertor extends FastjsonDataConvertor implements MsgConvertor, ConvertProvider {
168

@@ -19,23 +11,9 @@ public String mediaType() {
1911
return "application/json";
2012
}
2113

22-
@Override
23-
public <T> T toBean(Type type, InputStream in, Charset charset) {
24-
return JSON.parseObject(toString(in, charset), type);
25-
}
26-
2714
@Override
2815
public MsgConvertor getConvertor() {
2916
return new FastjsonMsgConvertor();
3017
}
3118

32-
@Override
33-
protected String toString(InputStream in, Charset charset) {
34-
try {
35-
return Okio.buffer(Okio.source(in)).readString(charset);
36-
} catch (IOException e) {
37-
throw new OkHttpsException("读取文本异常", e);
38-
}
39-
}
40-
4119
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cn.zhxu.okhttps.fastjson.FastjsonMsgConvertor
1+
cn.zhxu.okhttps.fastjson2.Fastjson2MsgConvertor

okhttps-fastjson/src/test/java/cn/zhxu/okhttps/fastjson/TestCase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import cn.zhxu.okhttps.test.JsonTestCases;
55
import org.junit.Test;
66

7-
87
public class TestCase {
98

109
@Test

okhttps-fastjson2/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# OkHttps FastJson
2+
3+
#### 介绍
4+
5+
基于 OkHttps 与 FastJson 集成扩展
6+
7+
8+
##### Maven
9+
10+
```xml
11+
<dependency>
12+
<groupId>com.ejlchina</groupId>
13+
<artifactId>okhttps-fastjson</artifactId>
14+
<version>3.5.3</version>
15+
</dependency>
16+
```
17+
18+
##### Gradle
19+
20+
```groovy
21+
implementation 'com.ejlchina:okhttps-fastjson:3.5.3'
22+
```
23+
24+
#### 更多请参阅 [http://okhttps.ejlchina.com/](http://okhttps.ejlchina.com/)

okhttps-fastjson2/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<artifactId>okhttps-fastjson2</artifactId>
5+
<name>OkHttps Fastjson2</name>
6+
<packaging>jar</packaging>
7+
8+
<parent>
9+
<groupId>com.ejlchina</groupId>
10+
<artifactId>okhttps-parent</artifactId>
11+
<version>3.5.3</version>
12+
</parent>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.ejlchina</groupId>
17+
<artifactId>okhttps</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>cn.zhxu</groupId>
22+
<artifactId>data-fastjson2</artifactId>
23+
<version>${data.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.ejlchina</groupId>
27+
<artifactId>okhttps-test</artifactId>
28+
<version>${project.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<finalName>okhttps-fastjson</finalName>
35+
</build>
36+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.zhxu.okhttps.fastjson2;
2+
3+
import cn.zhxu.data.fastjson2.Fastjson2DataConvertor;
4+
import cn.zhxu.okhttps.ConvertProvider;
5+
import cn.zhxu.okhttps.MsgConvertor;
6+
import cn.zhxu.okhttps.OkHttpsException;
7+
import com.alibaba.fastjson2.JSON;
8+
import okio.Okio;
9+
10+
import java.io.IOException;
11+
import java.io.InputStream;
12+
import java.lang.reflect.Type;
13+
import java.nio.charset.Charset;
14+
15+
public class Fastjson2MsgConvertor extends Fastjson2DataConvertor implements MsgConvertor, ConvertProvider {
16+
17+
@Override
18+
public String mediaType() {
19+
return "application/json";
20+
}
21+
22+
@Override
23+
public <T> T toBean(Type type, InputStream in, Charset charset) {
24+
return JSON.parseObject(toString(in, charset), type);
25+
}
26+
27+
@Override
28+
public MsgConvertor getConvertor() {
29+
return new Fastjson2MsgConvertor();
30+
}
31+
32+
@Override
33+
protected String toString(InputStream in, Charset charset) {
34+
try {
35+
return Okio.buffer(Okio.source(in)).readString(charset);
36+
} catch (IOException e) {
37+
throw new OkHttpsException("读取文本异常", e);
38+
}
39+
}
40+
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cn.zhxu.okhttps.fastjson2.Fastjson2MsgConvertor
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.zhxu.okhttps.fastjson2;
2+
3+
import cn.zhxu.okhttps.MsgConvertor;
4+
import cn.zhxu.okhttps.test.JsonTestCases;
5+
import org.junit.Test;
6+
7+
8+
public class TestCase {
9+
10+
@Test
11+
public void doTest() throws Exception {
12+
MsgConvertor msgConvertor = new Fastjson2MsgConvertor();
13+
new JsonTestCases(msgConvertor).run();
14+
}
15+
16+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<module>okhttps-gson</module>
1515
<module>okhttps-jackson</module>
1616
<module>okhttps-fastjson</module>
17+
<module>okhttps-fastjson2</module>
1718
<module>okhttps-test</module>
1819
</modules>
1920

0 commit comments

Comments
 (0)