本文整理匯總了Java中org.codehaus.jackson.map.module.SimpleModule.addSerializer方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleModule.addSerializer方法的具體用法?Java SimpleModule.addSerializer怎麽用?Java SimpleModule.addSerializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.map.module.SimpleModule
的用法示例。
在下文中一共展示了SimpleModule.addSerializer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JsonObjectMapperWriter
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的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();
}
}
示例2: load
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的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();
}
示例3: load
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的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();
}
示例4: load
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的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();
}
示例5: addSerializers
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
private void addSerializers() {
SimpleModule simpleModule = new SimpleModule("AHRDFModule", new Version(1,0, 0, null));
//simpleModule.addSerializer(new LangStringSerializer());
simpleModule.addSerializer(new XMLGregorianCalendarSerializer());
simpleModule.addSerializer(new OfferingSerializer());
simpleModule.addSerializer(EventType.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(EventStatus.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(Room.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(AttachmentType.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(ProductionType.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(VenueType.class, new AHRDFObjectSerializer());
simpleModule.addSerializer(Genre.class, new AHRDFObjectSerializer());
registerModule(simpleModule);
}
示例6: toJson
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
public static String toJson(Object object) {
ObjectMapper mapper = new ObjectMapper(new MyJsonFactory());
SimpleModule module = new SimpleModule("fullcalendar", new Version(1, 0, 0, null));
module.addSerializer(new DateTimeSerializer());
module.addSerializer(new LocalTimeSerializer());
mapper.registerModule(module);
mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
String json = null;
try {
json = mapper.writeValueAsString(object);
} catch (Exception e) {
throw new RuntimeException("Error encoding object: " + object + " into JSON string", e);
}
return json;
}
示例7: CustomJSONProvider
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
public CustomJSONProvider() {
super();
ObjectMapper mapper = new ObjectMapper();
SimpleModule myModule = new SimpleModule("MyOpenDaylightOFFlowJSONSerializerDeserializerModule", new Version(1, 0, 0, null));
myModule.addSerializer(new OpenDaylightOFFlowJSONSerializer()); // assuming OpenDaylightOFFlowJSONSerializer declares correct class to bind to
myModule.addDeserializer(OpenDaylightOFFlow.class, new OpenDaylightOFFlowJSONDeserializer());
myModule.addDeserializer(OpenDaylightOFFlowsWrapper.class, new OpenDaylightOFFlowsWrapperJSONDeserializer());
mapper.registerModule(myModule);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true);
// mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
super.setMapper(mapper);
}
示例8: CustomJSONProvider
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
public CustomJSONProvider() {
super();
ObjectMapper mapper = new ObjectMapper();
SimpleModule myModule = new SimpleModule("MyFloodlightOFFlowJSONSerializerDeserializerModule", new Version(1, 0, 0, null));
myModule.addSerializer(new FloodlightOFFlowJSONSerializer()); // assuming FloodlightOFFlowJSONSerializer declares correct class to bind to
myModule.addDeserializer(FloodlightOFFlow.class, new FloodlightOFFlowJSONDeserializer());
myModule.addDeserializer(FloodlightOFFlowsWrapper.class, new FloodlightOFFlowsWrapperJSONDeserializer());
mapper.registerModule(myModule);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true);
// mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
super.setMapper(mapper);
}
示例9: addJodaSerializers
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
/** Add Joda-Time serializers to a module. */
@SuppressWarnings({
"unchecked",
"rawtypes"
})
private static void addJodaSerializers(final SimpleModule module) {
for (final Entry<Class<?>, JsonSerializer<?>> serializer : new JodaSerializers().provide()) {
module.addSerializer((Class) serializer.getKey(), serializer.getValue());
}
module.addSerializer(Duration.class, DurationSerializer.create());
module.addSerializer(Instant.class, InstantSerializer.create());
module.addSerializer(Interval.class, IntervalSerializer.create());
module.addSerializer(LocalDate.class, LocalDateSerializer.create());
}
示例10: serializeToJson
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
private String serializeToJson(Object object, String attributesArray) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim2UserFilterModule", new Version(1, 0, 0, ""));
ListResponseUserSerializer serializer = new ListResponseUserSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(User.class, serializer);
mapper.registerModule(customScimFilterModule);
return mapper.writeValueAsString(object);
}
示例11: serializeToJson
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
private String serializeToJson(Object object, String attributesArray) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim2GroupFilterModule", new Version(1, 0, 0, ""));
ListResponseGroupSerializer serializer = new ListResponseGroupSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(Group.class, serializer);
mapper.registerModule(customScimFilterModule);
return mapper.writeValueAsString(object);
}
示例12: serializeToJson
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
private String serializeToJson(Object object, String attributesArray) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim2FidoDeviceFilterModule", new Version(1, 0, 0, ""));
ListResponseFidoDeviceSerializer serializer = new ListResponseFidoDeviceSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(FidoDevice.class, serializer);
mapper.registerModule(customScimFilterModule);
return mapper.writeValueAsString(object);
}
示例13: serialize
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
private String serialize(Serializable serializable) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customSchemaTypeAstractModule = new SimpleModule("CustomSchemaTypeAbstractModule", new Version(1, 0, 0, ""));
SchemaTypeAbstractSerializer serializer = new SchemaTypeAbstractSerializer();
customSchemaTypeAstractModule.addSerializer(SchemaType.class, serializer);
mapper.registerModule(customSchemaTypeAstractModule);
return mapper.writeValueAsString(serializable);
}
示例14: init
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
@SuppressWarnings({"rawtypes", "unchecked"})
private void init()
{
//clear content type
httpResponse.setContentType(null);
if (!initialized) {
Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
StringCodecs.loadConverters(codecs);
if (codecs != null) {
SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
try {
final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance();
sm.addSerializer(new SerializerBase(entry.getKey())
{
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException
{
jgen.writeString(codec.toString(value));
}
});
} catch (Exception ex) {
LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
}
}
objectMapper.registerModule(sm);
}
initialized = true;
}
}
示例15: addSerializer
import org.codehaus.jackson.map.module.SimpleModule; //導入方法依賴的package包/類
/**
* @param <T>
* @param class1
* @param jsonSerializer
*/
public <T> void addSerializer(final Class<T> clazz, final JsonSerializer<T> jsonSerializer) {
final SimpleModule mod = new SimpleModule("MyModule", new Version(1, 0, 0, null));
mod.addSerializer(clazz, new org.codehaus.jackson.map.JsonSerializer<T>() {
@Override
public void serialize(final T arg0, final JsonGenerator jgen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
jgen.writeRawValue(jsonSerializer.toJSonString(arg0));
}
}
);
mapper.registerModule(mod);
}