All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dongliu.requests.json.JsonProvider Maven / Gradle / Ivy

There is a newer version: 5.0.8
Show newest version
package net.dongliu.requests.json;

import javax.annotation.Nullable;
import java.io.*;
import java.lang.reflect.Type;
import java.nio.charset.Charset;

/**
 * Json provider
 *
 * @author Liu Dong
 */
public interface JsonProvider {

    /**
     * Serialize value to json, and write to writer
     */
    void marshal(Writer writer, @Nullable Object value) throws IOException;

    /**
     * Deserialize json from reader, with type
     */
    @Nullable
     T unmarshal(Reader reader, Type type) throws IOException;

    /**
     * Deserialize json from input stream, with charset and type.
     * This method is for FastJson due it has no api to unmarshal from Reader
     */
    @Nullable
    default  T unmarshal(InputStream inputStream, Charset charset, Type type) throws IOException {
        try (Reader reader = new InputStreamReader(inputStream, charset)) {
            return unmarshal(reader, type);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy