package com.fq.channel.sdk.base.exception;


import com.fq.threelib.gson.TypeAdapter;
import com.fq.threelib.gson.stream.JsonReader;
import com.fq.threelib.gson.stream.JsonToken;
import com.fq.threelib.gson.stream.JsonWriter;

import java.io.IOException;

/**
 * Created by Ethan on 2017/7/6.
 * 生成Json处理null 转换成 “” 相关类
 */

public class StringNullAdapter extends TypeAdapter<String> {
    @Override
    public String read(JsonReader reader) throws IOException {
        if (reader.peek() == JsonToken.NULL) {
            reader.nextNull();
            return "";
        }
        return reader.nextString();
    }

    @Override
    public void write(JsonWriter writer, String value) throws IOException {
        if (value == null) {
            writer.value("");
            return;
        }
        writer.value(value);
    }
}
