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


Java JsonSerialize类代码示例

本文整理汇总了Java中org.codehaus.jackson.map.annotate.JsonSerialize的典型用法代码示例。如果您正苦于以下问题:Java JsonSerialize类的具体用法?Java JsonSerialize怎么用?Java JsonSerialize使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonSerialize类属于org.codehaus.jackson.map.annotate包,在下文中一共展示了JsonSerialize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNewRowFromDb

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
public byte[] getNewRowFromDb() {
    boolean isFirstElement = mainId == null;
    Row row = inflateRow();
    if (row != null) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            mapper.getSerializationConfig().withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
            mapper.setVisibility(JsonMethod.ALL, JsonAutoDetect.Visibility.NONE);
            mapper.setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
            String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(row);
            json = isFirstElement ? "" + json : "," + json;
            return json.getBytes();
        } catch (Exception e) {
            throw new AqlException("Failed to convert Aql Result to JSON", e);
        }
    }
    return null;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:19,代码来源:AqlJsonStreamer.java

示例2: Jackson1Annotator

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
public Jackson1Annotator(GenerationConfig generationConfig) {
    super(generationConfig);
    switch (generationConfig.getInclusionLevel()) {
        case ALWAYS:
            inclusionLevel = JsonSerialize.Inclusion.ALWAYS;
            break;
        case NON_ABSENT:
            inclusionLevel = JsonSerialize.Inclusion.NON_NULL;
            break;
        case NON_DEFAULT:
            inclusionLevel = JsonSerialize.Inclusion.NON_DEFAULT;
            break;
        case NON_EMPTY:
            inclusionLevel = JsonSerialize.Inclusion.NON_EMPTY;
            break;
        case NON_NULL:
            inclusionLevel = JsonSerialize.Inclusion.NON_NULL;
            break;
        case USE_DEFAULTS:
            inclusionLevel = JsonSerialize.Inclusion.NON_NULL;
            break;
        default:
            inclusionLevel = JsonSerialize.Inclusion.NON_NULL;
            break;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Jackson1Annotator.java

示例3: CustomObjectMapper

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的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

示例4: jsonToStringIgnoreSpecialFields

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
/**
 * jsonToString exclude null data end edit fields
 *
 * @param model - model data to String
 * @return - model data with json format
 */
public static String jsonToStringIgnoreSpecialFields(RestModel model) {
    String[] ExcludedFieldsFromView = getExcludedFields(model);
    ObjectMapper specialMapper = new ObjectMapper();
    specialMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    String data = null;
    FilterProvider filters = new SimpleFilterProvider()
            .addFilter("exclude fields",
                    SimpleBeanPropertyFilter.serializeAllExcept(
                            (ExcludedFieldsFromView)));
    ObjectWriter writer = specialMapper.writer(filters);
    try {
        data = writer.writeValueAsString(model);
    } catch (IOException e) {
        log.debug(e.getMessage());
    }
    return data;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:24,代码来源:JsonUtil.java

示例5: buildJson

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
private String buildJson(Object object) {

        ObjectMapper mapper = new ObjectMapper();
        SerializationConfig serializationConfig = mapper.getSerializationConfig();
        serializationConfig = serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
        AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
        mapper.setSerializationConfig(serializationConfig);
        mapper.setAnnotationIntrospector(introspector);

        try {
            return mapper.writeValueAsString(object);
        } catch (IOException e) {
            log.warn("Can't marshal search criteria.");
            throw new RuntimeException("Failed inFolder build criteria json.", e);
        }
    }
 
开发者ID:Jaspersoft,项目名称:jrs-rest-java-client,代码行数:17,代码来源:BatchJobsOperationsAdapter.java

示例6: parseResult

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
private CallControlCallResultType parseResult(MultivaluedMap<String, String> queryParams, WebResource resource, boolean returnResult) throws JsonProcessingException, IOException {
	queryParams.add("output", "json");

	Builder builder = resource.queryParams(queryParams).getRequestBuilder();

	builder = builder.accept(javax.ws.rs.core.MediaType.APPLICATION_JSON);
	builder = builder.type(javax.ws.rs.core.MediaType.APPLICATION_JSON);
	builder = builder.cookie(JSESSIONID_WS);

	String resultStr = builder.get(String.class);

	ObjectMapper mapper = new ObjectMapper();
	mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
	JsonNode rootNode = mapper.readTree(resultStr);
	if(returnResult)
	{
		JsonNode ccr = rootNode.path("ExtActionResponse").path("structure").path("CallControlCallResult");
		return mapper.readValue(ccr, CallControlCallResultType.class);
	}
	else return null;
}
 
开发者ID:mcdjw,项目名称:sip-servlets,代码行数:23,代码来源:ASCCallControlClient.java

示例7: Jackson1InclusionLevelAlways

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelAlways() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "ALWAYS"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.ALWAYS));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例8: Jackson1InclusionLevelNonAbsent

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelNonAbsent() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "NON_ABSENT"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_NULL));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例9: Jackson1InclusionLevelNonDefault

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelNonDefault() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "NON_DEFAULT"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_DEFAULT));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例10: Jackson1InclusionLevelNonEmpty

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelNonEmpty() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "NON_EMPTY"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_EMPTY));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例11: Jackson1InclusionLevelNonNull

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelNonNull() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "NON_NULL"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_NULL));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例12: Jackson1InclusionLevelUseDefault

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelUseDefault() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1", "inclusionLevel", "USE_DEFAULTS"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_NULL));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例13: Jackson1InclusionLevelNotSet

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void Jackson1InclusionLevelNotSet() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("annotationStyle", "jackson1"));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    JsonSerialize jsonSerialize = (JsonSerialize) generatedType.getAnnotation(JsonSerialize.class);

    assertThat(jsonSerialize, is(notNullValue()));
    assertThat(jsonSerialize.include(), is(JsonSerialize.Inclusion.NON_NULL));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:InclusionLevelIT.java

示例14: JsonSerializer

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
/** Private constructor to hide the implicit public one. */
private JsonSerializer() {
	jsonMapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
	jsonMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
	jsonMapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, false);
	jsonMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	jsonMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
}
 
开发者ID:jmiddleton,项目名称:cassandra-fhir-index,代码行数:9,代码来源:JsonSerializer.java

示例15: getNullableObjectMapper

import org.codehaus.jackson.map.annotate.JsonSerialize; //导入依赖的package包/类
public static ObjectMapper getNullableObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();

    // mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
    // mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
    // mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // //mapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
    // mapper.configure(Feature.AUTO_CLOSE_SOURCE, false);
    // mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);

    SerializationConfig config = objectMapper.getSerializationConfig();
    config.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

    return objectMapper;
}
 
开发者ID:blusechen,项目名称:venus,代码行数:16,代码来源:ObjectMapperFactory.java


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