当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.configure方法代码示例

本文整理汇总了Java中org.codehaus.jackson.map.ObjectMapper.configure方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.configure方法的具体用法?Java ObjectMapper.configure怎么用?Java ObjectMapper.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: JsonObjectMapperWriter

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public JsonObjectMapperWriter(OutputStream output, boolean prettyPrint) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);

  // define a module
  SimpleModule module = new SimpleModule("Default Serializer",  
                                         new Version(0, 1, 1, "FINAL"));
  // add various serializers to the module
  //   add default (all-pass) serializer for all rumen specific data types
  module.addSerializer(DataType.class, new DefaultRumenSerializer());
  //   add a serializer to use object.toString() while serializing
  module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
  
  // register the module with the object-mapper
  mapper.registerModule(module);

  mapper.getJsonFactory();
  writer = mapper.getJsonFactory().createJsonGenerator(
      output, JsonEncoding.UTF8);
  if (prettyPrint) {
    writer.useDefaultPrettyPrinter();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:JsonObjectMapperWriter.java

示例3: read

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private void read(DataInput in) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(
      DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state deserializer
  module.addDeserializer(StatePair.class, new StateDeserializer());

  // register the module with the object-mapper
  mapper.registerModule(module);

  JsonParser parser = 
    mapper.getJsonFactory().createJsonParser((DataInputStream)in);
  StatePool statePool = mapper.readValue(parser, StatePool.class);
  this.setStates(statePool.getStates());
  parser.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:StatePool.java

示例4: write

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private void write(DataOutput out) throws IOException {
  // This is just a JSON experiment
  System.out.println("Dumping the StatePool's in JSON format.");
  ObjectMapper outMapper = new ObjectMapper();
  outMapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state serializer
  //module.addSerializer(State.class, new StateSerializer());

  // register the module with the object-mapper
  outMapper.registerModule(module);

  JsonFactory outFactory = outMapper.getJsonFactory();
  JsonGenerator jGen = 
    outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
  jGen.useDefaultPrettyPrinter();

  jGen.writeObject(this);
  jGen.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:StatePool.java

示例5: 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

示例6: getJsonObjectMapper

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * 获取统一的ObjectMapper.
 *
 * @return 统一的ObjectMapper.
 */
public static ObjectMapper getJsonObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    return objectMapper;
}
 
开发者ID:facetome,项目名称:smart_plan,代码行数:12,代码来源:ParserJson.java

示例7: jsonTree

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static JsonNode jsonTree(ObjectMapper m, String json) {
    try {
        JsonParser jp = factory.createJsonParser(new StringReader(json));
        m.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
        return m.readTree(jp);
    } catch (Exception e) {
        System.out.println(e);
    }
    return NULL_NODE;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:11,代码来源:JsonUtil.java

示例8: 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

示例9: JsonObjectMapperParser

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param path
 *          Path to the JSON data file, possibly compressed.
 * @param conf
 * @throws IOException
 */
public JsonObjectMapperParser(Path path, Class<? extends T> clazz,
    Configuration conf) throws IOException {
  mapper = new ObjectMapper();
  mapper.configure(
      DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  this.clazz = clazz;
  InputStream input = new PossiblyDecompressedInputStream(path, conf);
  jsonParser = mapper.getJsonFactory().createJsonParser(input);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:JsonObjectMapperParser.java

示例10: 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

示例11: ObjectMapperUtil

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private ObjectMapperUtil() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:7,代码来源:ObjectMapperUtil.java

示例12: toObject

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static <T> T toObject(String json, Class<T> targetType) throws Exception {
  ObjectMapper om = new ObjectMapper();
  om.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  return om.readValue(json, targetType);
}
 
开发者ID:Microsoft,项目名称:pai,代码行数:6,代码来源:WebCommon.java

示例13: JsonMapper

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public JsonMapper() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    //objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:6,代码来源:JsonMapper.java

示例14: createObjectMapper

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static ObjectMapper createObjectMapper() {
	ObjectMapper ret = new ObjectMapper();
	ret.configure(
			DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	return ret;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:7,代码来源:JSONUtils.java

示例15: JsonOutputter

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public JsonOutputter() {
    mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true);
    mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:7,代码来源:JsonOutputter.java


注:本文中的org.codehaus.jackson.map.ObjectMapper.configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。