當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectMapper.writeValue方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.map.ObjectMapper.writeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMapper.writeValue方法的具體用法?Java ObjectMapper.writeValue怎麽用?Java ObjectMapper.writeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.writeValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeObjectToJson

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:WriteJsonServletHandler.java

示例2: writeObjectToJson

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:17,代碼來源:WriteJsonServletHandler.java

示例3: pushKnowledgePackageToClients

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
public void pushKnowledgePackageToClients(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	String project=req.getParameter("project");
	project=Utils.decodeURL(project);
	String packageId=project+"/"+Utils.decodeURL(req.getParameter("packageId"));
	if(packageId.startsWith("/")){
		packageId=packageId.substring(1,packageId.length());
	}
	KnowledgePackage knowledgePackage=CacheUtils.getKnowledgeCache().getKnowledge(packageId);
	
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
	StringWriter writer=new StringWriter();
	mapper.writeValue(writer, new KnowledgePackageWrapper(knowledgePackage));
	String content=writer.getBuffer().toString();
	writer.close();
	StringBuffer sb=new StringBuffer();
	List<ClientConfig> clients=repositoryService.loadClientConfigs(project);
	int i=0;
	for(ClientConfig config:clients){
		if(i>0){
			sb.append("<br>");
		}
		boolean result=pushKnowledgePackage(packageId,content,config.getClient());
		if(result){
			sb.append("<span class=\"text-info\" style='line-height:30px'>推送到客戶端:"+config.getName()+":"+config.getClient()+" 成功</span>");
		}else{
			sb.append("<span class=\"text-danger\" style='line-height:30px'>推送到客戶端:"+config.getName()+":"+config.getClient()+" 失敗</span>");
		}
		i++;
	}
	Map<String,Object> map=new HashMap<String,Object>();
	map.put("info", sb.toString());
	writeObjectToJson(resp, map);
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:37,代碼來源:PackageServletHandler.java

示例4: writeObjectToJson

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:16,代碼來源:WriteJsonServletAction.java


注:本文中的org.codehaus.jackson.map.ObjectMapper.writeValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。