• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SerializationFeature类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.fasterxml.jackson.databind.SerializationFeature的典型用法代码示例。如果您正苦于以下问题:Java SerializationFeature类的具体用法?Java SerializationFeature怎么用?Java SerializationFeature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SerializationFeature类属于com.fasterxml.jackson.databind包,在下文中一共展示了SerializationFeature类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createObjectMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
    final YAMLFactory yamlFactory = new YAMLFactory()
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
        .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
        .configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);

    ObjectMapper mapper = new ObjectMapper(yamlFactory)
        .registerModule(new Jdk8Module())
        .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
        .enable(SerializationFeature.INDENT_OUTPUT)
        .disable(SerializationFeature.WRITE_NULL_MAP_VALUES);

    for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
        mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
    }

    return mapper;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:20,代码来源:YamlHelpers.java


示例2: createObjectMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static ObjectMapper createObjectMapper() {
    final YAMLFactory yamlFactory = new YAMLFactory()
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false)
        .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
        .configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true)
        .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false);

    ObjectMapper mapper = new ObjectMapper(yamlFactory)
        .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
        .enable(SerializationFeature.INDENT_OUTPUT)
        .disable(SerializationFeature.WRITE_NULL_MAP_VALUES);

    for (Step step : ServiceLoader.load(Step.class, YamlHelpers.class.getClassLoader())) {
        mapper.registerSubtypes(new NamedType(step.getClass(), step.getKind()));
    }

    return mapper;
}
 
开发者ID:syndesisio,项目名称:syndesis-integration-runtime,代码行数:19,代码来源:YamlHelpers.java


示例3: writeTypescriptConfig

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
private void writeTypescriptConfig() throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	mapper.enable(SerializationFeature.INDENT_OUTPUT);
	ObjectNode root = mapper.createObjectNode();
	ObjectNode compilerOptions = root.putObject("compilerOptions");
	compilerOptions.put("baseUrl", "");
	compilerOptions.put("declaration", true);
	compilerOptions.put("emitDecoratorMetadata", true);
	compilerOptions.put("experimentalDecorators", true);
	compilerOptions.put("module", "es6");
	compilerOptions.put("moduleResolution", "node");
	compilerOptions.put("sourceMap", true);
	compilerOptions.put("target", "es5");
	ArrayNode typeArrays = compilerOptions.putArray("typeRoots");
	typeArrays.add("node_modules/@types");
	ArrayNode libs = compilerOptions.putArray("lib");
	libs.add("es6");
	libs.add("dom");

	File outputSourceDir = new File(outputDir, config.getSourceDirectoryName());
	File file = new File(outputSourceDir, "tsconfig.json");
	file.getParentFile().mkdirs();
	mapper.writer().writeValue(file, root);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:25,代码来源:TSGenerator.java


示例4: IiifObjectMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public IiifObjectMapper() {
  this.checkJacksonVersion();

  // Don't include null properties
  this.setSerializationInclusion(Include.NON_NULL);

  // Both are needed to add `@context` to the top-level object
  this.disable(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS);
  this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  // Some array fields are unwrapped during serialization if they have only one value
  this.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

  // Register the problem handler
  this.addHandler(new ProblemHandler());

  // Disable writing dates as timestamps
  this.registerModule(new JavaTimeModule());
  this.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

  // Enable automatic detection of parameter names in @JsonCreators
  this.registerModule(new ParameterNamesModule());

  // Register the module
  this.registerModule(new IiifModule());
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:27,代码来源:IiifObjectMapper.java


示例5: testBadRegistration

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Test
public void testBadRegistration() throws Exception {
    RegisterDTO registerDTO = new RegisterDTO();
    registerDTO.setUsername("JonkiPro");
    registerDTO.setEmail("[email protected]");
    registerDTO.setPassword("password1");
    registerDTO.setPasswordAgain("password1");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
    String requestJson = ow.writeValueAsString(registerDTO);

    mockMvc
            .perform(post("/api/v1.0/register")
                         .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
                         .content(requestJson))
            .andExpect(status().isBadRequest());
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:20,代码来源:RegisterRestControllerTest.java


示例6: objectMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static ObjectMapper objectMapper() {
    return new ObjectMapper()
            // Property visibility
            .setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS)
            .setDefaultVisibility(JsonAutoDetect.Value.construct(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC))
            .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true)

            // Property naming and order
            .setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)

            // Customised de/serializers

            // Formats, locals, encoding, binary data
            .setDateFormat(new SimpleDateFormat("MM/dd/yyyy"))
            .setDefaultPrettyPrinter(new DefaultPrettyPrinter())
            .setLocale(Locale.CANADA);
}
 
开发者ID:readlearncode,项目名称:JSON-framework-comparison,代码行数:20,代码来源:RuntimeSampler.java


示例7: setUp

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    mapper = Jackson2ObjectMapperBuilder.json()
            .featuresToDisable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
            .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .build();
    mapper.findAndRegisterModules();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:DefaultAuthenticationTests.java


示例8: afterPropertiesSet

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception
{
    //Configure the objectMapper ready for use
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(module);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);  //or NON_EMPTY?
    // this is deprecated in jackson 2.9 and there is no straight replacement
    // https://github.com/FasterXML/jackson-databind/issues/1547
    objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    DateFormat DATE_FORMAT_ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    DATE_FORMAT_ISO8601.setTimeZone(TimeZone.getTimeZone("UTC"));
    objectMapper.setDateFormat(DATE_FORMAT_ISO8601);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:17,代码来源:JacksonHelper.java


示例9: initialize

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<EndpointConfiguration> bootstrap) {
  bootstrap.getObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

  bootstrap.addBundle(new SwaggerBundle<EndpointConfiguration>() {
    @Override
    protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(
        EndpointConfiguration configuration) {
      return configuration.swagger;
    }
  });
}
 
开发者ID:nblair,项目名称:continuous-performance-testing,代码行数:13,代码来源:EndpointApplication.java


示例10: extendMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的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


示例11: testCache

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Test
public void testCache() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";
    DeliveryClient client = new DeliveryClient(projectId);
    final boolean[] cacheHit = {false};
    client.setCacheManager(new CacheManager() {
        @Override
        public JsonNode resolveRequest(String requestUri, HttpRequestExecutor executor) throws IOException {
            Assert.assertEquals("https://deliver.kenticocloud.com/02a70003-e864-464e-b62c-e0ede97deb8c/items/on_roasts", requestUri);
            cacheHit[0] = true;
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.registerModule(new JSR310Module());
            objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
            return objectMapper.readValue(this.getClass().getResourceAsStream("SampleContentItem.json"), JsonNode.class);
        }
    });
    ContentItemResponse item = client.getItem("on_roasts");
    Assert.assertNotNull(item);
    Assert.assertTrue(cacheHit[0]);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:21,代码来源:DeliveryClientTest.java


示例12: JsonMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
private JsonMapper() {
    // calls the default constructor
    super();

    // configures ISO8601 formatter for date without time zone
    // the used format is 'yyyy-MM-dd'
    setDateFormat(new SimpleDateFormat(FMT_ISO_LOCAL_DATE));

    // enforces to skip null and empty values in the serialized JSON output
    setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

    // enforces to skip null references in the serialized output of map
    configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

    // enables serialization failures, when mapper encounters unknown properties names
    configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    // configures the format to prevent writing of the serialized output for dates
    // instances as timestamps; any date should be written in ISO format
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:JsonMapper.java


示例13: objectToString

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static String objectToString (final Object object) {
    if (object == null) {
        return null;
    }

    try {
        final StringWriter stringWriter = new StringWriter();

        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        objectMapper.writeValue(stringWriter, object);

        return stringWriter.toString().replaceAll(System.getProperty("line.separator"), "");
    } catch (IOException ex) {
        STRINGUTIL_LOGGER.info("Sorry. had a error on during Object to String. ("+ex.toString()+")");
        return null;
    }
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:20,代码来源:StringObjectUtils.java


示例14: deserializeWithStrategy

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Test
public void deserializeWithStrategy() throws Exception {
  ObjectMapper
      mapper =
      new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
          .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
          .setPropertyNamingStrategy(new EsPropertyNamingStrategy(
              EsDailySnapshotInstance.class, EsInstanceStore.class))
          .configure(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING, true);

  EsDailySnapshotInstance inst = mapper.readValue(doc, EsDailySnapshotInstance.class);
  Assert.assertEquals("coreapp-webapp-prod-0a018ef5", inst.getName());
  Assert.assertEquals("fixed", inst.getLifecycle());
  Assert.assertTrue(inst.getLaunchTime() != null);

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:17,代码来源:EsPropertyNamingStrategyTest.java


示例15: JsonMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public JsonMapper() {
    // calls the default constructor
    super();

    // configures ISO8601 formatter for date without time zone
    // the used format is 'yyyy-MM-dd'
    super.setDateFormat(new SimpleDateFormat(FMT_ISO_LOCAL_DATE));

    // enforces to skip null and empty values in the serialized JSON output
    super.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

    // enforces to skip null references in the serialized output of Map
    super.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

    // enables serialization failures, when mapper encounters unknown properties names
    super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);

    // configures the format to prevent writing of the serialized output for java.util.Date
    // instances as timestamps. any date should be written in ISO format
    super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:JsonMapper.java


示例16: configureerMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
private void configureerMapper() {
    // Configuratie
    this.disable(MapperFeature.AUTO_DETECT_CREATORS);
    this.disable(MapperFeature.AUTO_DETECT_FIELDS);
    this.disable(MapperFeature.AUTO_DETECT_GETTERS);
    this.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    this.disable(MapperFeature.AUTO_DETECT_SETTERS);

    // Default velden niet als JSON exposen (expliciet annoteren!)
    setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE);
    this.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    this.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);

    // serialization
    this.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    this.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);

    // deserialization
    this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:22,代码来源:BrpJsonObjectMapper.java


示例17: jackson2ObjectMapperBuilder

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilder() {

    return builder -> {
        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
        df.setTimeZone(tz);

        builder
                .failOnEmptyBeans(false)
                .failOnUnknownProperties(false)
                .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .dateFormat(df);

    };
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:17,代码来源:DefaultJacksonConfiguration.java


示例18: EclipseParser

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
/**
 * Creates a new EclipseParser
 *
 * @param sourceFile String of source file to read
 * @param outJ       JSON parsed out
 * @throws IOException when file can't be opened or errors in reading/writing
 */
public EclipseParser(String sourceFile, PrintStream outJ, boolean prettyprint) throws IOException {

    File file = new File(sourceFile);
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    char[] source = IOUtils.toCharArray(reader);
    reader.close();
    this.parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final JsonFactory jsonF = new JsonFactory();
    jG = jsonF.createGenerator(outJ);
    if (prettyprint) {
        jG.setPrettyPrinter(new DefaultPrettyPrinter());
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    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(ASTNode.class, new NodeSerializer());
    mapper.registerModule(module);
}
 
开发者ID:bblfsh,项目名称:java-driver,代码行数:31,代码来源:eclipseParser.java


示例19: map

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Override
public <T> T map(String json, Class<T> clazz) {
    if (null == json) {
        throw new IllegalArgumentException("Can not map empty json");
    }
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    JsonUnmarshaller jsonUnmarshaller = new FixedDefaultJsonUnmarshaller(mapper);
    try {
        return jsonUnmarshaller.unmarshal(clazz, json);
    } catch (IOException e) {
        log.warn("Error during mapping", e);
        return null;
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:17,代码来源:ElasticPathStrategy.java


示例20: createDefaultMapper

import com.fasterxml.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static ObjectMapper createDefaultMapper() {

		final ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(Include.NON_NULL);
		mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

		SimpleModule module = new SimpleModule();
		module.addSerializer(Transaction.class, new TransactionSerializer());
		module.addDeserializer(Transaction.class, new TransactionDeserializer());
		module.addSerializer(Difficulty.class, new DifficultySerializer());
		module.addDeserializer(Difficulty.class, new DifficultyDeserializer());
		module.addSerializer(Block.class, new BlockSerializer());
		module.addDeserializer(Block.class, new BlockDeserializer());
		mapper.registerModule(module);

		return mapper;

	}
 
开发者ID:EonTechnology,项目名称:server,代码行数:21,代码来源:ObjectMapperProvider.java



注:本文中的com.fasterxml.jackson.databind.SerializationFeature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Path类代码示例发布时间:2022-05-20
下一篇:
Java VisibleForTesting类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap