當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleModule.addSerializer方法代碼示例

本文整理匯總了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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:JacksonConverterFactoryTest.java

示例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;
}
 
開發者ID:Lambda-3,項目名稱:Stargraph,代碼行數:14,代碼來源:ObjectSerializer.java

示例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);
    }
}
 
開發者ID:cslee00,項目名稱:cfn-core,代碼行數:27,代碼來源:JsonCloudFormationGenerator.java

示例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;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:20,代碼來源:JacksonModule.java

示例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());

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:RestEasyServlet.java

示例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);
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi-api,代碼行數:23,代碼來源:ConvertersConfiguration.java

示例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();
    }
}
 
開發者ID:KayLerch,項目名稱:alexa-skills-kit-states-java,代碼行數:27,代碼來源:AlexaStateModel.java

示例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);
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:19,代碼來源:JacksonObjectMapperConfig.java

示例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);
}
 
開發者ID:aws,項目名稱:aws-iot-device-sdk-java,代碼行數:20,代碼來源:AbstractAwsIotDevice.java

示例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);
    }
}
 
開發者ID:GJWT,項目名稱:javaOIDCMsg,代碼行數:15,代碼來源:JWTCreator.java

示例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);
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:8,代碼來源:GitObjectMapperConfigurator.java

示例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);
}
 
開發者ID:braineering,項目名稱:ares,代碼行數:18,代碼來源:SimpleReportJsonMapper.java

示例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);
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:15,代碼來源:ObjectMapperTrim.java

示例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);
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:12,代碼來源:ResponseWriter.java

示例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);
}
 
開發者ID:braineering,項目名稱:ares,代碼行數:16,代碼來源:BotCommandJsonMapper.java


注:本文中的com.fasterxml.jackson.databind.module.SimpleModule.addSerializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。