com.jianggujin.http.response.JJsonResponse Maven / Gradle / Ivy
package com.jianggujin.http.response;
import java.io.IOException;
import java.io.InputStream;
import com.jianggujin.http.util.JDataUtils;
/**
* JSON响应
*
* @author jianggujin
*
*/
public class JJsonResponse extends JAbstractResponse {
private Class> target = null;
private String charset;
private static JJsonResolver resolver = null;
public JJsonResponse(Class> target) {
this.target = target;
}
public JJsonResponse(Class> target, String charset) {
this.charset = charset;
this.target = target;
}
@Override
protected void dealData(InputStream stream) throws IOException {
String charset = (this.charset == null || this.charset.length() == 0)
? JDataUtils.getCharsetFromContentType(this.getHeader("Content-Type"))
: this.charset;
this.data = resolver != null ? resolver.resolve(target, stream, charset) : null;
}
/**
* 设置解析器
*
* @param resolver
*/
public static void setResolver(JJsonResolver resolver) {
JJsonResponse.resolver = resolver;
}
/**
* JSON解析器
*
* @author jianggujin
*
*/
public static interface JJsonResolver {
Object resolve(Class> clazz, InputStream stream, String charset);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy