List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl)
From source file:io.fouad.jtb.core.utils.JsonUtils.java
public static String toJson(Object javaObject) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); return mapper.writeValueAsString(javaObject); }
From source file:gaffer.function.ConsumerFunctionTest.java
private static ObjectMapper createObjectMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); return mapper; }
From source file:org.craftercms.social.migration.util.scripting.ScriptUtils.java
public static String toJson(Object o) throws JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.getSerializationConfig().without(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.getSerializationConfig().with(SerializationFeature.WRITE_NULL_MAP_VALUES, SerializationFeature.WRITE_EMPTY_JSON_ARRAYS); return mapper.writeValueAsString(o); }
From source file:com.basistech.rosette.dm.jackson.AnnotatedDataModelModule.java
/** * Register the Annotated Data Model Jackson module on an {@link ObjectMapper}. * @param mapper the mapper.// www. j a va 2s . co m * @return the same mapper, for convenience. */ public static ObjectMapper setupObjectMapper(ObjectMapper mapper) { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); final AnnotatedDataModelModule module = new AnnotatedDataModelModule(); mapper.registerModule(module); return mapper; }
From source file:org.obiba.mica.web.rest.TestUtil.java
/** * Convert an object to JSON byte array. * * @param object the object to convert/*w ww. j a v a 2 s . c o m*/ * @return the JSON byte array * @throws IOException */ public static byte[] convertObjectToJsonBytes(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsBytes(object); }
From source file:io.spring.initializr.actuate.stat.ProjectGenerationStatPublisher.java
private static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper; }
From source file:org.tynamo.resteasy.modules.SwaggerModule.java
@Contribute(javax.ws.rs.core.Application.class) public static void jacksonJsonProviderSetup(Configuration<Object> singletons) { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); /**/*from w w w . j a v a 2s . c o m*/ * "publishedDate": 1384267338786, * vs * "publishedDate": "2013-11-12T14:42:18.786+0000", */ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JacksonJaxbJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider(); jacksonJsonProvider.setMapper(mapper); singletons.add(jacksonJsonProvider); }
From source file:org.mongojack.internal.MongoJackModule.java
/** * Configure the given object mapper to be used with MongoJack. Please call * this method rather than calling//from w w w .j a v a 2s .co m * objectMapper.with(MongoJacksonMapperModule.INSTANCE), because Jacksons * module system doesn't allow MongoJack to do all the configuration it * needs to do. This method will do that configuration though. * * @param objectMapper * The object mapper to configure * @return This object mapper (for chaining) */ public static ObjectMapper configure(ObjectMapper objectMapper) { objectMapper.registerModule(INSTANCE); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return objectMapper; }
From source file:nl.talsmasoftware.enumerables.support.json.jackson2.EnumerableJackson2ModuleTest.java
static ObjectMapper mapperWith(Module module) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerModule(module);// w ww . j ava 2 s . c o m return mapper; }
From source file:de.javagl.jgltf.browser.MenuNodesCreator.java
/** * Write the given list of {@link MenuNode} objects as JSON to the * given output stream. The caller is responsible for closing the * given stream.//from w w w .j av a2s . c o m * * @param menuNodes The menu nodes * @param outputStream The output stream * @throws IOException If an IO error occurs */ private static void write(List<? extends MenuNode> menuNodes, OutputStream outputStream) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.writeValue(outputStream, menuNodes); }