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


Java SerializationFeature類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.SerializationFeature的典型用法代碼示例。如果您正苦於以下問題:Java SerializationFeature類的具體用法?Java SerializationFeature怎麽用?Java SerializationFeature使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SerializationFeature類屬於com.fasterxml.jackson.databind包,在下文中一共展示了SerializationFeature類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例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)
        .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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例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


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