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


Java SerializationConfig類代碼示例

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


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

示例1: writeInternal

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator jsonGenerator =
			this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

	// A workaround for JsonGenerators not applying serialization features
	// https://github.com/FasterXML/jackson-databind/issues/12
	if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
		jsonGenerator.useDefaultPrettyPrinter();
	}

	try {
		if (this.jsonPrefix != null) {
			jsonGenerator.writeRaw(this.jsonPrefix);
		}
		this.objectMapper.writeValue(jsonGenerator, object);
	}
	catch (JsonProcessingException ex) {
		throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:MappingJacksonHttpMessageConverter.java

示例2: writeObjectToJson

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的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

示例3: configureFeature

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
private void configureFeature(Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		this.objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationConfig.Feature) {
		this.objectMapper.configure((SerializationConfig.Feature) feature, enabled);
	}
	else if (feature instanceof DeserializationConfig.Feature) {
		this.objectMapper.configure((DeserializationConfig.Feature) feature, enabled);
	}
	else {
		throw new IllegalArgumentException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:JacksonObjectMapperFactoryBean.java

示例4: JsonObjectMapperWriter

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的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

示例5: write

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的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

示例6: writeObjectToJson

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的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

示例7: CustomObjectMapper

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
   public CustomObjectMapper()
{
	super();
	this.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	this.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
	this.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
	
	this.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); 
	this.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
	this.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY);

	final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
	
	// make deserializer use JAXB annotations (only)
	this.setAnnotationIntrospector(introspector);
	
	// TODO leverage NamingStrategy to make reponse attributes more Java-like
	//this.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
}
 
開發者ID:SAP,項目名稱:SAP-cloud-dqm-sample-java,代碼行數:23,代碼來源:CustomObjectMapper.java

示例8: load

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {

    log.info(" load() ");

    Meta meta = new Meta();
    meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);

    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);

    mapper.writeValueAsString(createDummyUser());

    return serializer.getSchemaType();
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:24,代碼來源:UserCoreLoadingStrategy.java

示例9: load

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {

    log.info(" load() ");

    Meta meta = new Meta();
    meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);

    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
    serializer.setSchemaType(schemaType);
    groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
    mapper.registerModule(groupCoreLoadingStrategyModule);

    mapper.writeValueAsString(createDummyGroup());

    return serializer.getSchemaType();
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:24,代碼來源:GroupCoreLoadingStrategy.java

示例10: load

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {

	log.info(" load() ");

	Meta meta = new Meta();
	meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
	meta.setResourceType("Schema");
	schemaType.setMeta(meta);

	// Use serializer to walk the class structure
	ObjectMapper mapper = new ObjectMapper();
	mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
	SimpleModule userCoreLoadingStrategyModule = new SimpleModule("FidoDeviceCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
	SchemaTypeFidoDeviceSerializer serializer = new SchemaTypeFidoDeviceSerializer();
	serializer.setSchemaType(schemaType);
	userCoreLoadingStrategyModule.addSerializer(FidoDevice.class, serializer);
	mapper.registerModule(userCoreLoadingStrategyModule);

	mapper.writeValueAsString(createDummyFidoDevice());

	return serializer.getSchemaType();
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:24,代碼來源:FidoDeviceCoreLoadingStrategy.java

示例11: JsonModelSerializer

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
public JsonModelSerializer(boolean doNullValues, Class<T> serializedType) {
		super();
		objectMapper = new ObjectMapper();
		AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
		// make serializer use JAXB annotations (only)
		SerializationConfig sc = objectMapper.getSerializationConfig().withAnnotationIntrospector(introspector);
		sc.with(SerializationConfig.Feature.INDENT_OUTPUT);
		
		if (!doNullValues) {
			sc.without(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES);
			sc.without(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS);
			sc = sc.withSerializationInclusion(Inclusion.NON_EMPTY);
		}
		
		objectMapper.setSerializationConfig(sc);
//		if (!doNullValues) {
//			objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY);
//		}
	}
 
開發者ID:ina-foss,項目名稱:amalia-model,代碼行數:20,代碼來源:JsonModelSerializer.java

示例12: open

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
/**
 * Open a JSON output file
 * The file output may be derived from many input sources
 *  
 * @param name
 * @param string 
 * @throws XMLStreamException
 * @throws IOException
 */
public void open(File file) throws XMLStreamException, IOException {
	
       // Mapped convention
	JsonFactory f = new JsonFactory();
	try {
		generator = f.createJsonGenerator(new FileWriter(file));
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
		generator.setCodec(mapper);
		generator.useDefaultPrettyPrinter();

		rootNode = mapper.createObjectNode();
		rootNode.put("name", "odfestyles");
		rootArray = rootNode.putArray(CHILDREN_TAG);
		
	} catch (JsonGenerationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
}
 
開發者ID:hammyau,項目名稱:ODFExplorer,代碼行數:30,代碼來源:StylesJSONWriter.java

示例13: open

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
public void open(File file) throws XMLStreamException, IOException {
	
       // Mapped convention
	JsonFactory f = new JsonFactory();
	try {
		generator = f.createJsonGenerator(new FileWriter(file));
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
		generator.setCodec(mapper);
		generator.useDefaultPrettyPrinter();

		rootNode = mapper.createObjectNode();
		rootNode.put("name", "odfpaths");
		rootArray = rootNode.putArray(CHILDREN_TAG);
		
	} catch (JsonGenerationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
}
 
開發者ID:hammyau,項目名稱:ODFExplorer,代碼行數:21,代碼來源:XPathJSONWriter.java

示例14: getPostSummary

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
private String getPostSummary(Object o) {
	String s = "";
	ObjectMapper mapper = new ObjectMapper();
	
	mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
	if (o != null) {
		try {
			if (o instanceof ImportSummaries)
				s += mapper.writeValueAsString(mapper.readTree(mapper.writeValueAsString((ImportSummaries) o)));
			else if (o instanceof DHISImportSummary)
				s += mapper.writeValueAsString((DHISImportSummary) o);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	return s;
}
 
開發者ID:jembi,項目名稱:openmrs-module-dhisconnector,代碼行數:20,代碼來源:DHISConnectorServiceImpl.java

示例15: getJson

import org.codehaus.jackson.map.SerializationConfig; //導入依賴的package包/類
public String getJson(String objName, Object obj) {

//        List<SimpleClassBasedVisibility> visibilities = getPropertyGroupBasedClassBasedVisibilities(product);

//        if (visibilities == null || visibilities.size() == 0) {
//            return null;
//        }
//        CustomVisibilityChecker visibilityChecker = new CustomVisibilityChecker(visibilities);

//        ObjectWriter objectMapper = createObjectMapper(visibilityChecker);

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
        String ret = getJson(objName, obj, mapper.writer());
        return ret;
    }
 
開發者ID:vahidooo,項目名稱:quranic-graph,代碼行數:17,代碼來源:BaseWS.java


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