本文整理汇总了Java中org.codehaus.jackson.map.SerializationConfig类的典型用法代码示例。如果您正苦于以下问题:Java SerializationConfig类的具体用法?Java SerializationConfig怎么用?Java SerializationConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializationConfig类属于org.codehaus.jackson.map包,在下文中一共展示了SerializationConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeInternal
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
JsonGenerator jsonGenerator =
this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
// A workaround for JsonGenerators not applying serialization features
// https://github.com/FasterXML/jackson-databind/issues/12
if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
jsonGenerator.useDefaultPrettyPrinter();
}
try {
if (this.jsonPrefix != null) {
jsonGenerator.writeRaw(this.jsonPrefix);
}
this.objectMapper.writeValue(jsonGenerator, object);
}
catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
示例2: writeObjectToJson
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
resp.setHeader("Access-Control-Allow-Origin", "*");
resp.setContentType("text/json");
resp.setCharacterEncoding("UTF-8");
ObjectMapper mapper=new ObjectMapper();
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
OutputStream out = resp.getOutputStream();
try {
mapper.writeValue(out, obj);
} finally {
out.flush();
out.close();
}
}
示例3: configureFeature
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
private void configureFeature(Object feature, boolean enabled) {
if (feature instanceof JsonParser.Feature) {
this.objectMapper.configure((JsonParser.Feature) feature, enabled);
}
else if (feature instanceof JsonGenerator.Feature) {
this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
}
else if (feature instanceof SerializationConfig.Feature) {
this.objectMapper.configure((SerializationConfig.Feature) feature, enabled);
}
else if (feature instanceof DeserializationConfig.Feature) {
this.objectMapper.configure((DeserializationConfig.Feature) feature, enabled);
}
else {
throw new IllegalArgumentException("Unknown feature class: " + feature.getClass().getName());
}
}
示例4: JsonObjectMapperWriter
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
public JsonObjectMapperWriter(OutputStream output, boolean prettyPrint) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
// define a module
SimpleModule module = new SimpleModule("Default Serializer",
new Version(0, 1, 1, "FINAL"));
// add various serializers to the module
// add default (all-pass) serializer for all rumen specific data types
module.addSerializer(DataType.class, new DefaultRumenSerializer());
// add a serializer to use object.toString() while serializing
module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
// register the module with the object-mapper
mapper.registerModule(module);
mapper.getJsonFactory();
writer = mapper.getJsonFactory().createJsonGenerator(
output, JsonEncoding.UTF8);
if (prettyPrint) {
writer.useDefaultPrettyPrinter();
}
}
示例5: write
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
private void write(DataOutput out) throws IOException {
// This is just a JSON experiment
System.out.println("Dumping the StatePool's in JSON format.");
ObjectMapper outMapper = new ObjectMapper();
outMapper.configure(
SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
// define a module
SimpleModule module = new SimpleModule("State Serializer",
new Version(0, 1, 1, "FINAL"));
// add the state serializer
//module.addSerializer(State.class, new StateSerializer());
// register the module with the object-mapper
outMapper.registerModule(module);
JsonFactory outFactory = outMapper.getJsonFactory();
JsonGenerator jGen =
outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
jGen.useDefaultPrettyPrinter();
jGen.writeObject(this);
jGen.close();
}
示例6: writeObjectToJson
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
resp.setHeader("Access-Control-Allow-Origin", "*");
resp.setContentType("text/json");
resp.setCharacterEncoding("UTF-8");
ObjectMapper mapper=new ObjectMapper();
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
OutputStream out = resp.getOutputStream();
try {
mapper.writeValue(out, obj);
} finally {
out.flush();
out.close();
}
}
示例7: CustomObjectMapper
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的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);
}
示例8: load
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
serializer.setSchemaType(schemaType);
userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
mapper.registerModule(userCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyUser());
return serializer.getSchemaType();
}
示例9: load
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
serializer.setSchemaType(schemaType);
groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
mapper.registerModule(groupCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyGroup());
return serializer.getSchemaType();
}
示例10: load
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
@Override
public SchemaType load(ApplicationConfiguration applicationConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(applicationConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule userCoreLoadingStrategyModule = new SimpleModule("FidoDeviceCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeFidoDeviceSerializer serializer = new SchemaTypeFidoDeviceSerializer();
serializer.setSchemaType(schemaType);
userCoreLoadingStrategyModule.addSerializer(FidoDevice.class, serializer);
mapper.registerModule(userCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyFidoDevice());
return serializer.getSchemaType();
}
示例11: JsonModelSerializer
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
public JsonModelSerializer(boolean doNullValues, Class<T> serializedType) {
super();
objectMapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make serializer use JAXB annotations (only)
SerializationConfig sc = objectMapper.getSerializationConfig().withAnnotationIntrospector(introspector);
sc.with(SerializationConfig.Feature.INDENT_OUTPUT);
if (!doNullValues) {
sc.without(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES);
sc.without(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS);
sc = sc.withSerializationInclusion(Inclusion.NON_EMPTY);
}
objectMapper.setSerializationConfig(sc);
// if (!doNullValues) {
// objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY);
// }
}
示例12: open
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
/**
* Open a JSON output file
* The file output may be derived from many input sources
*
* @param name
* @param string
* @throws XMLStreamException
* @throws IOException
*/
public void open(File file) throws XMLStreamException, IOException {
// Mapped convention
JsonFactory f = new JsonFactory();
try {
generator = f.createJsonGenerator(new FileWriter(file));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
generator.setCodec(mapper);
generator.useDefaultPrettyPrinter();
rootNode = mapper.createObjectNode();
rootNode.put("name", "odfestyles");
rootArray = rootNode.putArray(CHILDREN_TAG);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例13: open
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
public void open(File file) throws XMLStreamException, IOException {
// Mapped convention
JsonFactory f = new JsonFactory();
try {
generator = f.createJsonGenerator(new FileWriter(file));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
generator.setCodec(mapper);
generator.useDefaultPrettyPrinter();
rootNode = mapper.createObjectNode();
rootNode.put("name", "odfpaths");
rootArray = rootNode.putArray(CHILDREN_TAG);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例14: getPostSummary
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
private String getPostSummary(Object o) {
String s = "";
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
if (o != null) {
try {
if (o instanceof ImportSummaries)
s += mapper.writeValueAsString(mapper.readTree(mapper.writeValueAsString((ImportSummaries) o)));
else if (o instanceof DHISImportSummary)
s += mapper.writeValueAsString((DHISImportSummary) o);
}
catch (IOException e) {
e.printStackTrace();
}
}
return s;
}
示例15: getJson
import org.codehaus.jackson.map.SerializationConfig; //导入依赖的package包/类
public String getJson(String objName, Object obj) {
// List<SimpleClassBasedVisibility> visibilities = getPropertyGroupBasedClassBasedVisibilities(product);
// if (visibilities == null || visibilities.size() == 0) {
// return null;
// }
// CustomVisibilityChecker visibilityChecker = new CustomVisibilityChecker(visibilities);
// ObjectWriter objectMapper = createObjectMapper(visibilityChecker);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
String ret = getJson(objName, obj, mapper.writer());
return ret;
}