本文整理匯總了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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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;
}