當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。