List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl)
From source file:de.taimos.dvalin.jaxrs.MapperFactory.java
public static ObjectMapper createDefault() { ObjectMapper m = new ObjectMapper(); m.registerModule(new JodaModule()); m.registerModule(new GuavaModule()); m.setSerializationInclusion(Include.NON_NULL); m.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); m.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); m.enable(MapperFeature.AUTO_DETECT_GETTERS); return m;/*from w w w .j a va 2 s .c o m*/ }
From source file:info.archinnov.achilles.json.DefaultJacksonMapper.java
private static ObjectMapper defaultJacksonMapper() { ObjectMapper defaultMapper = new ObjectMapper(); defaultMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); defaultMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); defaultMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); defaultMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary)); return defaultMapper; }
From source file:com.twitter.ambrose.util.JSONUtil.java
private static ObjectMapper newMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE); mapper.disable(SerializationFeature.CLOSE_CLOSEABLE); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); Reflections reflections = new Reflections("com.twitter.ambrose"); Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class); mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()])); return mapper; }
From source file:de.cinovo.cloudconductor.api.lib.helper.MapperFactory.java
/** * @return the object mapper/*w w w. j a v a 2s . co m*/ */ public static ObjectMapper createDefault() { ObjectMapper m = new ObjectMapper(); m.registerModule(new JodaModule()); m.registerModule(new GuavaModule()); m.setSerializationInclusion(Include.NON_NULL); m.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); m.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); m.enable(MapperFeature.AUTO_DETECT_GETTERS); return m; }
From source file:je.backit.rest.JacksonContextResolver.java
private static ObjectMapper init() { ObjectMapper om = new ObjectMapper(); om.registerModule(new JSR310Module()); om.registerModule(new JooqModule()); om.setSerializationInclusion(JsonInclude.Include.NON_NULL); om.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false) .configure(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM, false); om.configure(WRITE_DATES_AS_TIMESTAMPS, false); om.setVisibilityChecker(om.getSerializationConfig().getDefaultVisibilityChecker() .withIsGetterVisibility(NONE).withGetterVisibility(NONE).withFieldVisibility(ANY)); return om;/*from www. ja v a 2 s .c o m*/ }
From source file:org.lable.rfc3881.auditlogger.serialization.ObjectMapperFactory.java
/** * Configures an {@link ObjectMapper} instance with the serialization strategies needed for this project. * * @return An object-mapper./*from w ww . jav a 2 s.c o m*/ */ public static ObjectMapper getObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new RFC3881Module()); objectMapper.registerModule(new JodaModule()); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); return objectMapper; }
From source file:it.eng.spagobi.studio.console.model.bo.JsonTemplateGenerator.java
public static String transformToJson(Object bean) throws SavingEditorException { String result = null;//from w w w . j a va 2 s .com try { ObjectMapper mapper = new ObjectMapper(); //This option exclude object with null value from the serialization mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //mapper.writeValueAsString(bean); result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(bean); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:com.basistech.rosette.examples.ExampleBase.java
/** * Converts a response to JSON string//from w w w .j a v a2 s. com * * @param response {@link com.basistech.rosette.apimodel.Response Response} from RosetteAPI * @return the json string. * @throws JsonProcessingException if the Jackson library throws an error serializing. */ protected static String responseToJson(Response response) throws JsonProcessingException { ObjectMapper mapper = ApiModelMixinModule.setupObjectMapper(new ObjectMapper()); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(response); }
From source file:org.sahli.asciidoc.confluence.publisher.client.ConfluencePublisher.java
private static ConfluencePublisherMetadata readConfig(String configPath) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); try {/*from ww w .jav a 2 s . co m*/ return objectMapper.readValue(new File(configPath), ConfluencePublisherMetadata.class); } catch (IOException e) { throw new RuntimeException("Could not read metadata", e); } }
From source file:org.hawkular.datamining.rest.json.JacksonConfig.java
public static void initializeObjectMapper(ObjectMapper mapper) { mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES); mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); ObjectMapperConfig.config(mapper);/*from ww w . ja v a2 s.c om*/ }