当前位置: 首页>>代码示例>>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;未经允许,请勿转载。