本文整理汇总了Java中com.fasterxml.jackson.databind.module.SimpleModule.addSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleModule.addSerializer方法的具体用法?Java SimpleModule.addSerializer怎么用?Java SimpleModule.addSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.module.SimpleModule
的用法示例。
在下文中一共展示了SimpleModule.addSerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Before public void setUp() {
SimpleModule module = new SimpleModule();
module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
mapper.setVisibilityChecker(mapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(JacksonConverterFactory.create(mapper))
.build();
service = retrofit.create(Service.class);
}
示例2: createMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public static ObjectMapper createMapper(KBId kbId) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(Fact.class, new FactSerializer(kbId));
module.addDeserializer(Fact.class, new FactDeSerializer(kbId));
module.addSerializer(PropertyEntity.class, new PropertySerializer(kbId));
module.addDeserializer(PropertyEntity.class, new PropertyDeserializer(kbId));
module.addSerializer(InstanceEntity.class, new InstanceSerializer(kbId));
module.addDeserializer(InstanceEntity.class, new InstanceDeserializer(kbId));
module.addSerializer(ClassEntity.class, new ClassSerializer(kbId));
mapper.registerModule(module);
return mapper;
}
示例3: generate
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Override
public void generate(Object obj, OutputStream os, boolean prettyPrint) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, false);
mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
if (prettyPrint) {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
SimpleModule module = new SimpleModule();
module.addSerializer(CfnObject.class, new CfnObjectSerializer(resourceSpecificationService));
module.addSerializer(IntrinsicFunction.class, new IntrinsicFunctionSerializer());
mapper.registerModule(module);
try {
mapper.writeValue(os, obj);
os.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例4: createJacksonModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Creates Crnk Jackson module with all required serializers.<br />
* Adds the {@link LinksInformationSerializer} if <code>serializeLinksAsObjects</code> is set to <code>true</code>.
*
* @param serializeLinksAsObjects flag which decides whether the {@link LinksInformationSerializer} should be added as
* additional serializer or not.
*
* @return {@link com.fasterxml.jackson.databind.Module} with custom serializers
*/
public static SimpleModule createJacksonModule(boolean serializeLinksAsObjects) {
SimpleModule simpleModule = new SimpleModule(JSON_API_JACKSON_MODULE_NAME,
new Version(1, 0, 0, null, null, null));
simpleModule.addSerializer(new ErrorDataSerializer());
simpleModule.addDeserializer(ErrorData.class, new ErrorDataDeserializer());
if (serializeLinksAsObjects) {
simpleModule.addSerializer(new LinksInformationSerializer());
}
return simpleModule;
}
示例5: extendMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Override
public void extendMapper(ObjectMapper mapper)
{
SimpleModule restModule = new SimpleModule("RestModule", new Version(1, 0, 0, null));
// TODO this probably should be somewhere else, but it can't be in
// com.tle.core.jackson
// as that would make it dependent on equella i18n
restModule.addSerializer(new I18NSerializer());
mapper.registerModule(restModule);
mapper.registerModule(new JavaTypesModule());
mapper.registerModule(new RestStringsModule());
mapper.setSerializationInclusion(Include.NON_NULL);
// dev mode!
if( DebugSettings.isDebuggingMode() )
{
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
mapper.setDateFormat(new ISO8061DateFormatWithTZ());
}
示例6: jsonV1Converter
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter jsonV1Converter(ObjectMapper objectMapper) {
// Serialize numbers as strings
objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
// Serialize booleans as strings
SimpleModule booleanAsString = new SimpleModule("BooleanAsString");
booleanAsString.addSerializer(Boolean.class, new JsonSerializer<Boolean>() {
@Override public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeString(value.toString());
}
});
objectMapper.registerModule(booleanAsString);
objectMapper.addMixIn(ContextElement.class, EntityIdMixIn.class);
objectMapper.addMixIn(AppendContextElementResponse.class, EntityIdMixIn.class);
return new MappingJackson2HttpMessageConverter(objectMapper);
}
示例7: toJSON
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Returns a json with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid
* in the given scope
* @param scope The scope a AlexaStateSave-annotated field must have or be part of to be considered in the returned json
* @throws AlexaStateException Wraps all inner exceptions and gives you context related to handler and model
* @return A json-string with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid
*/
public String toJSON(final AlexaScope scope) throws AlexaStateException {
// for each scope there is a custom json serializer so initialize the one which corresponds to the given scope
final AlexaStateSerializer serializer = AlexaScope.APPLICATION.equals(scope) ?
new AlexaAppStateSerializer() : AlexaScope.USER.equals(scope) ?
new AlexaUserStateSerializer() : new AlexaSessionStateSerializer();
// associate a mapper with the serializer
final ObjectMapper mapper = new ObjectMapper();
final SimpleModule module = new SimpleModule();
module.addSerializer(this.getClass(), serializer);
mapper.registerModule(module);
try {
// serialize model which only contains those fields tagged with the given scope
return mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
final String error = String.format("Error while serializing model of '%1$s' as Json.", this);
log.error(error, e);
throw AlexaStateException.create(error).withCause(e).withModel(this).build();
}
}
示例8: JacksonObjectMapperConfig
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public JacksonObjectMapperConfig() {
super();
this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
//this.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); 不增加,避免key值为null,而避免节点消失
this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
//this.setSerializationInclusion(Include.NON_EMPTY); //对象转字符串时,只转化非空字段 zjs 需要占位
//SimpleModule module = new SimpleModule();
SimpleModule module = new SimpleModule("HTML XSS Serializer",
new Version(1, 0, 0, "FINAL", "com.simbest", "ep-jsonmodule"));
module.addSerializer(new JsonHtmlXssSerializer(String.class));
module.addDeserializer(Date.class, new CustomJsonDateDeseralizer());
// Add more here ...
registerModule(module);
}
示例9: AbstractAwsIotDevice
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
protected AbstractAwsIotDevice(String thingName) {
this.thingName = thingName;
reportedProperties = getDeviceProperties(true, false);
updatableProperties = getDeviceProperties(false, true);
commandManager = new AwsIotDeviceCommandManager(this);
deviceSubscriptions = new ConcurrentHashMap<>();
for (String topic : getDeviceTopics()) {
deviceSubscriptions.put(topic, false);
}
jsonObjectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(AbstractAwsIotDevice.class, new AwsIotJsonSerializer());
jsonObjectMapper.registerModule(module);
localVersion = new AtomicLong(-1);
}
示例10: JWTCreator
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
private JWTCreator(Algorithm algorithm, Map<String, Object> headerClaims, Map<String, Object> payloadClaims) throws JWTCreationException {
this.algorithm = algorithm;
try {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ClaimsHolder.class, new PayloadSerializer());
mapper.registerModule(module);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
headerJson = mapper.writeValueAsString(headerClaims);
payloadJson = mapper.writeValueAsString(new ClaimsHolder(payloadClaims));
} catch (JsonProcessingException e) {
throw new JWTCreationException("Some of the Claims couldn't be converted to a valid JSON format.", e);
}
}
示例11: configure
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Override
public void configure(ObjectMapper objectMapper) {
SimpleModule module = new SimpleModule("GitModule");
module.addSerializer(ObjectId.class, new ObjectIdSerializer());
module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
objectMapper.registerModule(module);
}
示例12: SimpleReportJsonMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Initializes the JSON constructor.
*/
public SimpleReportJsonMapper() {
super();
SimpleModule module = new SimpleModule();
module.addDeserializer(SimpleReport.class, SimpleReportDeserializer.getInstance());
module.addDeserializer(AppConfiguration.class, AppConfigurationDeserializer.getInstance());
module.addDeserializer(Controller.class, ControllerDeserializer.getInstance());
module.addDeserializer(HttpFloodAttack.class, HttpFloodAttackDeserializer.getInstance());
module.addSerializer(SimpleReport.class, SimpleReportSerializer.getInstance());
module.addSerializer(AppConfiguration.class, AppConfigurationSerializer.getInstance());
module.addSerializer(Controller.class, ControllerSerializer.getInstance());
module.addSerializer(HttpFloodAttack.class, HttpFloodAttackSerializer.getInstance());
super.registerModule(module);
super.enable(SerializationFeature.INDENT_OUTPUT);
}
示例13: ObjectMapperTrim
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Default constructor overriding the default annotation introspector.
*/
public ObjectMapperTrim() {
setAnnotationIntrospector(CUSTOM_ANNOTATION_INTROSPECTOR);
final SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null, null, null));
testModule.addDeserializer(Date.class, DateDeserializer.INSTANCE);
testModule.addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE);
testModule.addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);
testModule.addSerializer(Date.class, DateSerializer.INSTANCE);
testModule.addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE);
testModule.addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE);
registerModule(testModule);
}
示例14: ResponseWriter
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
public ResponseWriter(final OutputStream out) {
this.out = out;
this.mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
SimpleModule module = new SimpleModule();
module.addSerializer(CompilationUnit.class, new CompilationUnitSerializer());
mapper.registerModule(module);
}
示例15: BotCommandJsonMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Initializes the JSON constructor.
*/
public BotCommandJsonMapper() {
super();
SimpleModule module = new SimpleModule();
module.addSerializer(BotCommand.class, BotCommandSerializer.getInstance());
module.addSerializer(HttpFloodAttack.class, HttpFloodAttackSerializer.getInstance());
module.addSerializer(Controller.class, ControllerSerializer.getInstance());
module.addDeserializer(BotCommand.class, BotCommandDeserializer.getInstance());
module.addDeserializer(HttpFloodAttack.class, HttpFloodAttackDeserializer.getInstance());
module.addDeserializer(Controller.class, ControllerDeserializer.getInstance());
super.registerModule(module);
super.enable(SerializationFeature.INDENT_OUTPUT);
}