Example usage for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion

List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion.

Prototype

public ObjectMapper setSerializationInclusion(JsonInclude.Include incl) 

Source Link

Document

Method for setting defalt POJO property inclusion strategy for serialization.

Usage

From source file:svnserver.ext.web.server.WebServer.java

@NotNull
public static ObjectMapper createJsonMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;
}

From source file:org.nohope.jongo.JacksonProcessor.java

@Nonnull
private static ObjectMapper createPreConfiguredMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ColorModule());

    mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(AUTO_DETECT_GETTERS, false);
    mapper.configure(AUTO_DETECT_SETTERS, false);
    mapper.setSerializationInclusion(NON_NULL);
    mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY));

    mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL,
            JsonTypeInfo.Id.CLASS.getDefaultPropertyName());

    final SimpleModule module = new SimpleModule("jongo", Version.unknownVersion());
    module.addKeySerializer(Object.class, ComplexKeySerializer.S_OBJECT);
    module.addKeyDeserializer(String.class, ComplexKeyDeserializer.S_OBJECT);
    module.addKeyDeserializer(Object.class, ComplexKeyDeserializer.S_OBJECT);

    //addBSONTypeSerializers(module);

    mapper.registerModule(module);//from   www. j  a va  2s .  c  o  m
    return mapper;
}

From source file:parser.JsonWriter.java

/**
 * Creates json file for the cloudDSFPlus with all new attributes.
 * //from  w  ww. j  a v  a  2  s  .c  o m
 * @param workbook
 * @throws JsonGenerationException
 * @throws JsonMappingException
 * @throws IOException
 */
private static void writeCloudDSFPlusJson(XSSFWorkbook workbook)
        throws JsonGenerationException, JsonMappingException, IOException {
    // instantiate parser for CloudDSFPlus and read excel
    CloudDSFPlusParser cloudDSFPlusParser = new CloudDSFPlusParser(workbook);
    CloudDSF cdsf = cloudDSFPlusParser.readExcel();
    // check the internal consistency and if successfull serialize data
    if (cdsf.checkSanity()) {
        // Helper Method
        // cdsf.printCloudDSF();
        // Jackson objectmapper and settings
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        // Ignore missing getters to serialize all values
        mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                .withGetterVisibility(JsonAutoDetect.Visibility.NONE));
        mapper.setSerializationInclusion(Include.NON_NULL);
        // create json structure
        JsonNode rootNode = mapper.createObjectNode();
        ((ObjectNode) rootNode).putPOJO("cdsfPlus", cdsf);
        ((ObjectNode) rootNode).putPOJO("links", cdsf.getInfluencingDecisions());
        ((ObjectNode) rootNode).putPOJO("outcomeLinks", cdsf.getInfluencingOutcomes());
        // Serialize CloudDSFPlus into json file
        File file = new File("cloudDSFPlus.json");
        mapper.writeValue(file, rootNode);
        System.out.println("Knowledge Base has been successfully verified and exported");
    } else {
        // knowledge base is not valid abort serialization
        System.out.println("The knowledge base is not valid");
    }
}

From source file:com.currencyfair.onesignal.OneSignal.java

private static OneSignalComms oneSignal() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    objectMapper.setSerializationInclusion(Include.NON_EMPTY);
    JacksonDecoder decoder = new JacksonDecoder(objectMapper);
    return Feign.builder().encoder(new JacksonEncoder(objectMapper)).decoder(decoder).decode404()
            .errorDecoder(new OneSignalErrorDecoder(decoder)).logger(new Slf4jLogger()).logLevel(Level.FULL)
            .target(OneSignalComms.class, "https://onesignal.com/api/v1");
}

From source file:ubicrypt.core.Utils.java

public static void configureMapper(final ObjectMapper mapper) {
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new SimpleModule("ubicrypt module") {
        {//from  w w w  .  j  a  v  a 2  s.  c o m
            addSerializer(new PGPKValueSerializer(PGPKValue.class));
            addDeserializer(PGPKValue.class, new PGPKValueDeserializer(PGPKValue.class));
            addSerializer(new PathSerializer(Path.class));
            addDeserializer(Path.class, new PathDeserializer(Path.class));
        }
    });
    mapper.registerModule(new AfterburnerModule());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}

From source file:keywhiz.testing.JsonHelpers.java

/**
 * Customized ObjectMapper for common settings.
 *
 * @return customized object mapper//  w  w w  . ja  va2  s  .  co m
 */
private static ObjectMapper customizeObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new LogbackModule());
    mapper.registerModule(new GuavaExtrasModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;
}

From source file:com.tectonica.thirdparty.Jackson2.java

public static ObjectMapper createPropsMapper() {
    ObjectMapper mapper = new ObjectMapper();

    // limit to props only
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.ANY);

    // general configuration
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

    return mapper;
}

From source file:com.tectonica.thirdparty.Jackson2.java

public static ObjectMapper createFieldsMapper() {
    ObjectMapper mapper = new ObjectMapper();

    // limit to fields only
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);

    // general configuration
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

    return mapper;
}

From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java

public static String updateMobileFormDesign(FormModel formModel) {
    MobileFormComponent mobileFormComponent = new MobileFormComponent();
    mobileFormComponent.setId(formModel.getName());
    mobileFormComponent.setTitle(formModel.getTitle());
    mobileFormComponent.setContainer(true);
    try {/*from   ww w  .j a v  a2 s  . c om*/
        for (FieldModel field : formModel.getParameters()) {
            MobileFormComponent m = MobileFieldModelUtil.getMobileFormComponent(field, null);
            mobileFormComponent.getComponents().add(m);
        }
        //            for (FileModel file : formModel.getFiles()) {
        //                String line = FileModelUtil.getFormDesignElement(file);
        //                if (!line.isEmpty()) designBuilder.append(line).append(System.lineSeparator());
        //            }
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL);
        return mapper.writeValueAsString(mobileFormComponent);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return null;
}

From source file:com.netflix.conductor.contribs.http.HttpTask.java

private static ObjectMapper objectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
    om.setSerializationInclusion(Include.NON_NULL);
    om.setSerializationInclusion(Include.NON_EMPTY);
    return om;/*from  w  ww . j a v  a2s  .c  o m*/
}