本文整理汇总了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();
}
示例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;
}
示例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) {
}
}
}
}
示例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();
}
示例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;
}