fairnet/src/main/java/seed/com/gtm/util/JSONView.java

73 lines
2.0 KiB
Java

package seed.com.gtm.util;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONValue;
import org.springframework.web.servlet.view.AbstractView;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
public class JSONView extends AbstractView{
protected Log log = LogFactory.getLog(this.getClass());
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("text/plain;charset=UTF-8");
Map<String, Object> map = new HashMap<String, Object>();
Set<String> keySet = model.keySet();
Iterator<String> iterator = keySet.iterator();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = model.get(key);
//log.warn("json변환전 값형태>>>>"+value.getClass().getName());
if (key.startsWith("encodingFilter."))
continue;
if (key.startsWith("openSessionInViewFilter."))
continue;
if (key.startsWith("multipartFilter."))
continue;
if (key.startsWith("org."))
continue;
if (key.startsWith("javax."))
continue;
if (key.startsWith("criteria"))
continue;
if (key.startsWith("SitemeshRobot"))
continue;
if (key.startsWith("com."))
continue;
if (key.startsWith("Csrf"))
continue;
if (key.startsWith("csrftoken"))
continue;
if (key.startsWith("clipSlist"))
continue;
if(value.getClass().getName().startsWith("[Ljava.lang.String")){
map.put(key, model.get(key).toString());
}else{
map.put(key, model.get(key));
}
}
String json = JSONValue.toJSONString(map);
log.warn("###" + json);
PrintWriter out = response.getWriter();
out.write(json);
out.flush();
out.close();
}
}