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


Java JsonSerialize.Inclusion方法代碼示例

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


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

示例1: writeValueAsString

import org.codehaus.jackson.map.annotate.JsonSerialize; //導入方法依賴的package包/類
public String writeValueAsString(Object value,
		JsonSerialize.Inclusion inc) throws IOException,
		JsonGenerationException, JsonMappingException {
	if (inc == null) {
		return super.writeValueAsString(value);
	}
	// alas, we have to pull the recycler directly here...
	SegmentedStringWriter sw = new SegmentedStringWriter(
			_jsonFactory._getBufferRecycler());
	writeValueWithConf(_jsonFactory.createJsonGenerator(sw), value,
			inc);
	return sw.getAndClear();
}
 
開發者ID:neoremind,項目名稱:fountain,代碼行數:14,代碼來源:JsonUtils.java

示例2: writeValueAsBytes

import org.codehaus.jackson.map.annotate.JsonSerialize; //導入方法依賴的package包/類
public byte[] writeValueAsBytes(Object value,
        JsonSerialize.Inclusion inc) throws IOException,
        JsonGenerationException, JsonMappingException {
    if (inc == null) {
        return super.writeValueAsBytes(value);
    }
    // alas, we have to pull the recycler directly here...
    ByteArrayBuilder bb = new ByteArrayBuilder(_jsonFactory._getBufferRecycler());
    writeValueWithConf(_jsonFactory.createJsonGenerator(bb, JsonEncoding.UTF8), value,inc);
    byte[] result = bb.toByteArray();
    bb.release();
    return result;
}
 
開發者ID:neoremind,項目名稱:fountain,代碼行數:14,代碼來源:JsonUtils.java

示例3: writeValueWithConf

import org.codehaus.jackson.map.annotate.JsonSerialize; //導入方法依賴的package包/類
private void writeValueWithConf(JsonGenerator jgen, Object value,
		JsonSerialize.Inclusion inc) throws IOException,
		JsonGenerationException, JsonMappingException {
	
	SerializationConfig cfg = copySerializationConfig();
	cfg = cfg.withSerializationInclusion(inc);
	
	// [JACKSON-96]: allow enabling pretty printing for ObjectMapper
	// directly
	if (cfg.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
		jgen.useDefaultPrettyPrinter();
	}
	// [JACKSON-282]: consider Closeable
	if (cfg.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE)
			&& (value instanceof Closeable)) {
		configAndWriteCloseable(jgen, value, cfg);
		return;
	}
	boolean closed = false;
	try {
		_serializerProvider.serializeValue(cfg, jgen, value,
				_serializerFactory);
		closed = true;
		jgen.close();
	} finally {
		/*
		 * won't try to close twice; also, must catch exception (so it
		 * will not mask exception that is pending)
		 */
		if (!closed) {
			try {
				jgen.close();
			} catch (IOException ioe) {
			}
		}
	}
}
 
開發者ID:neoremind,項目名稱:fountain,代碼行數:38,代碼來源:JsonUtils.java

示例4: updateGenerator

import org.codehaus.jackson.map.annotate.JsonSerialize; //導入方法依賴的package包/類
/**
 * Update the generator with a default codec and pretty printer
 *
 * @param jsonFactory   Factory to set as codec
 * @param jsonGenerator Generator to configure
 */
private static void updateGenerator(JsonFactory jsonFactory, JsonGenerator jsonGenerator) {
    ObjectMapper mapper = new ObjectMapper(jsonFactory);

    //Update the annotation interceptor to also include jaxb annotations as a second choice
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector() {

        /**
         * BUG FIX:
         * By contract, if findSerializationInclusion didn't encounter any annotations that should change the
         * inclusion value, it should return the default value it has received; but actually returns null, which
         * overrides the NON_NULL option we set.
         * The doc states issue JACKSON-256 which was supposed to be fixed in 1.5.0. *twilight zone theme song*
         */

        @Override
        public JsonSerialize.Inclusion findSerializationInclusion(Annotated a, JsonSerialize.Inclusion defValue) {
            JsonSerialize.Inclusion inclusion = super.findSerializationInclusion(a, defValue);
            if (inclusion == null) {
                return defValue;
            }
            return inclusion;
        }
    };
    AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
    mapper.getSerializationConfig().setAnnotationIntrospector(pair);
    mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

    jsonGenerator.setCodec(mapper);
    jsonGenerator.useDefaultPrettyPrinter();
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:38,代碼來源:JacksonFactory.java

示例5: findSerializationInclusion

import org.codehaus.jackson.map.annotate.JsonSerialize; //導入方法依賴的package包/類
public JsonSerialize.Inclusion findSerializationInclusion(Annotated paramAnnotated, JsonSerialize.Inclusion paramInclusion)
{
  JsonSerialize localJsonSerialize = (JsonSerialize)paramAnnotated.getAnnotation(JsonSerialize.class);
  if (localJsonSerialize != null)
    return localJsonSerialize.include();
  JsonWriteNullProperties localJsonWriteNullProperties = (JsonWriteNullProperties)paramAnnotated.getAnnotation(JsonWriteNullProperties.class);
  if (localJsonWriteNullProperties != null)
  {
    if (localJsonWriteNullProperties.value())
      return JsonSerialize.Inclusion.ALWAYS;
    return JsonSerialize.Inclusion.NON_NULL;
  }
  return paramInclusion;
}
 
開發者ID:zhangjianying,項目名稱:12306-android-Decompile,代碼行數:15,代碼來源:JacksonAnnotationIntrospector.java


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