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

com.github.df.restypass.http.converter.StringResponseConverter Maven / Gradle / Ivy

The newest version!
package com.github.df.restypass.http.converter;

import java.lang.reflect.Type;

/**
 * String类型响应的解析类
 * Created by darrenfu on 17-7-19.
 */
public class StringResponseConverter implements ResponseConverter {

    private static final String TEXT_PLAIN = "text/plain";


    @Override
    public boolean support(Type type, String contentType) {
        if (contentType == null) {
            return false;
        }
        if (!contentType.startsWith(TEXT_PLAIN)) {
            return false;
        }

        if (type instanceof Class && type != String.class) {
            return false;
        }

        return true;
    }

    @Override
    public String convert(byte[] body, Type type, String contentType) {
        return new String(body, getCharset(contentType));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy