Retrofit-Converter-FastJSON 使用教程

Retrofit-Converter-FastJSON 使用教程

retrofit-converter-fastjsonretrofit-converter-fastjson项目地址:https://gitcode.com/gh_mirrors/re/retrofit-converter-fastjson

1. 项目的目录结构及介绍

Retrofit-Converter-FastJSON 项目的目录结构如下:

retrofit-converter-fastjson/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── org/
│   │   │       └── ligboy/
│   │   │           └── retrofit2/
│   │   │               └── fastjson/
│   │   │                   ├── FastJsonCallAdapterFactory.java
│   │   │                   ├── FastJsonConverterFactory.java
│   │   │                   └── FastJsonResponseBodyConverter.java
│   │   └── resources/
│   └── test/
│       ├── java/
│       │   └── org/
│       │       └── ligboy/
│       │           └── retrofit2/
│       │               └── fastjson/
│       │                   └── FastJsonConverterFactoryTest.java
│       └── resources/
├── .gitignore
├── LICENSE
├── README.md
└── pom.xml

目录结构介绍:

  • src/main/java/org/ligboy/retrofit2/fastjson/:包含项目的主要源代码文件。

    • FastJsonCallAdapterFactory.java:用于处理 Retrofit 的 CallAdapter。
    • FastJsonConverterFactory.java:核心文件,用于将 FastJSON 集成到 Retrofit 中。
    • FastJsonResponseBodyConverter.java:用于处理响应体的转换。
  • src/test/java/org/ligboy/retrofit2/fastjson/:包含测试代码文件。

    • FastJsonConverterFactoryTest.java:用于测试 FastJsonConverterFactory 的功能。
  • .gitignore:Git 忽略文件配置。

  • LICENSE:项目许可证文件。

  • README.md:项目说明文档。

  • pom.xml:Maven 项目配置文件。

2. 项目的启动文件介绍

项目的启动文件主要是 FastJsonConverterFactory.java,它是将 FastJSON 集成到 Retrofit 中的核心文件。以下是该文件的简要介绍:

package org.ligboy.retrofit2.fastjson;

import com.alibaba.fastjson.JSON;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

public final class FastJsonConverterFactory extends Converter.Factory {

    public static FastJsonConverterFactory create() {
        return new FastJsonConverterFactory();
    }

    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
        return new FastJsonResponseBodyConverter<>(type);
    }

    @Override
    public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
        return new FastJsonRequestBodyConverter<>();
    }
}

启动文件介绍:

  • FastJsonConverterFactory:继承自 Converter.Factory,用于创建响应体和请求体的转换器。
  • responseBodyConverter:用于创建响应体转换器。
  • requestBodyConverter:用于创建请求体转换器。

3. 项目的配置文件介绍

项目的配置文件主要是 pom.xml,它是 Maven 项目的配置文件。以下是该文件的简要介绍:

<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.ligboy.retrofit2</groupId>
    <artifactId>converter-fastjson</artifactId>
    <version>2.1.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <!-- Retrofit 依赖 -->
       

retrofit-converter-fastjsonretrofit-converter-fastjson项目地址:https://gitcode.com/gh_mirrors/re/retrofit-converter-fastjson

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

常樱沙Vigour

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值