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


Java JsonInclude類代碼示例

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


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

示例1: createObjectMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的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: annotationStyleMoshi1ProducesMoshi1Annotations

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void annotationStyleMoshi1ProducesMoshi1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException, NoSuchFieldException {

    Class generatedType = schemaRule.generateAndCompile("/json/examples/torrent.json", "com.example",
            config("annotationStyle", "moshi1",
                    "propertyWordDelimiters", "_",
                    "sourceType", "json"))
            .loadClass("com.example.Torrent");

    assertThat(schemaRule.getGenerateDir(), not(containsText("org.codehaus.jackson")));
    assertThat(schemaRule.getGenerateDir(), not(containsText("com.fasterxml.jackson")));
    assertThat(schemaRule.getGenerateDir(), not(containsText("com.google.gson")));
    assertThat(schemaRule.getGenerateDir(), not(containsText("@SerializedName")));
    assertThat(schemaRule.getGenerateDir(), containsText("com.squareup.moshi"));
    assertThat(schemaRule.getGenerateDir(), containsText("@Json"));

    Method getter = generatedType.getMethod("getBuild");

    assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(nullValue()));
    assertThat(generatedType.getAnnotation(JsonInclude.class), is(nullValue()));
    assertThat(getter.getAnnotation(JsonProperty.class), is(nullValue()));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:Moshi1IT.java

示例3: customAnnotatorCanBeAppliedAlongsideCoreAnnotator

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void customAnnotatorCanBeAppliedAlongsideCoreAnnotator() throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example",
            config("customAnnotator", DeprecatingAnnotator.class.getName()));

    Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");

    Method getter = generatedType.getMethod("getA");

    assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue()));
    assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue()));
    assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue()));

    assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
    assertThat(generatedType.getAnnotation(Deprecated.class), is(notNullValue()));
    assertThat(getter.getAnnotation(Deprecated.class), is(notNullValue()));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:CustomAnnotatorIT.java

示例4: JsonMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的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

示例5: convertObjectToJsonBytes

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
    module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
開發者ID:klask-io,項目名稱:klask-io,代碼行數:24,代碼來源:TestUtil.java

示例6: initializeMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
private static ObjectMapper initializeMapper() {
    return new ObjectMapper()
            .registerModule(new JavaTimeModule())

            .disable(MapperFeature.AUTO_DETECT_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_CREATORS)
            .disable(MapperFeature.AUTO_DETECT_SETTERS)
            .disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_FIELDS)
            .disable(MapperFeature.DEFAULT_VIEW_INCLUSION)
            .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE)
            .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
            .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)

            // serialization
            .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
            .enable(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID)
            .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

            // deserialization
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:25,代碼來源:JsonMapper.java

示例7: SiloTemplateResolver

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
public SiloTemplateResolver(Class<T> classType) {
    ObjectMapper m = new ObjectMapper();
    m.registerModule(new GuavaModule());
    m.registerModule(new LogbackModule());
    m.registerModule(new GuavaExtrasModule());
    m.registerModule(new JodaModule());
    m.registerModule(new JSR310Module());
    m.registerModule(new AfterburnerModule());
    m.registerModule(new FuzzyEnumModule());
    m.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    m.setSubtypeResolver(new DiscoverableSubtypeResolver());

    //Setup object mapper to ignore the null properties when serializing the objects
    m.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    //Lets be nice and allow additional properties by default.  Allows for more flexible forward/backward 
    //compatibility and works well with jackson addtional properties feature for serialization
    m.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);

    this.classType = classType;
    this.mapper = m;
}
 
開發者ID:cvent,項目名稱:pangaea,代碼行數:22,代碼來源:SiloTemplateResolver.java

示例8: objectMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的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

示例9: JsonMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的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

示例10: afterPropertiesSet

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的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

示例11: createMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
private ObjectMapper createMapper(final boolean indent) {
//        final SimpleModule module = new SimpleModule();
//        module.addSerializer(Double.class, new MyDoubleSerialiser());

        final ObjectMapper mapper = new ObjectMapper();
//        mapper.registerModule(module);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
        mapper.configure(SerializationFeature.INDENT_OUTPUT, indent);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        // Enabling default typing adds type information where it would otherwise be ambiguous, i.e. for abstract classes
//        mapper.enableDefaultTyping();

        return mapper;
    }
 
開發者ID:gchq,項目名稱:stroom-query,代碼行數:17,代碼來源:TestSerialisation.java

示例12: parseExportedVariables

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
public void parseExportedVariables(PrintStream logger, Run<?, ?> build, String output) throws IOException {

        if (exportVariablesString == null) {
            return;
        }
        if (exportVariablesString.trim().equals("")) {
            return;
        }
        logger.println("Transforming to environment variables: " + exportVariablesString);
        HashMap<String, String> exportVariablesNames = com.azure.azurecli.helpers.Utils.parseExportedVariables(exportVariablesString);
        HashMap<String, String> exportVariables = new HashMap<>();

        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

        JsonNode rootNode = mapper.readTree(output);
        for (Map.Entry<String, String> var
                :
                exportVariablesNames.entrySet()) {

            String value = rootNode.at(var.getKey()).asText();
            exportVariables.put(var.getValue(), value);
        }
        com.azure.azurecli.helpers.Utils.setEnvironmentVariables(build, exportVariables);
    }
 
開發者ID:jenkinsci,項目名稱:azure-cli-plugin,代碼行數:26,代碼來源:Command.java

示例13: initializeObjectMapper

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
/**
 * Initialize object mapper.
 *
 * @return the object mapper
 */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:16,代碼來源:AbstractJacksonBackedJsonSerializer.java

示例14: JacksonContextResolver

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
public JacksonContextResolver() throws Exception {
    this.objectMapper = new ObjectMapper()
        .registerModule(new Jdk8Module())
        .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
        .configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true)
        .configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
}
 
開發者ID:syndesisio,項目名稱:syndesis-verifier,代碼行數:8,代碼來源:JacksonContextResolver.java

示例15: createState

import com.fasterxml.jackson.annotation.JsonInclude; //導入依賴的package包/類
public void createState(BrowserSessionId browserSessionId, String matchingId, long timeoutMillis, BrowserSessionStateExtractionConfig browserSessionStateExtractionConfig) {

            Map<String, Object>  params = ImmutableMap.of("optMatchingId", matchingId, "extractionConfig", browserSessionStateExtractionConfig);
            ObjectMapper mapper = new ObjectMapper();
            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            Optional<HttpResponse> r = sendPOST(createStateTemplate, ImmutableMap.of("browserSessionId", browserSessionId.toString()), mapper.valueToTree(params)).getOptHttpResponse();
            waitForStateExtractionResponse(timeoutMillis, r);
        }
 
開發者ID:webmate-io,項目名稱:webmate-sdk-java,代碼行數:9,代碼來源:BrowserSessionClient.java


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