List of usage examples for com.fasterxml.jackson.databind ObjectMapper disable
public ObjectMapper disable(SerializationFeature f)
From source file:org.sonatype.siesta.jackson2.ObjectMapperProvider.java
private ObjectMapper create() { ObjectMapper mapper = new ObjectMapper(); // Pretty print output mapper.enable(SerializationFeature.INDENT_OUTPUT); // Write dates as ISO-8601 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // Ignore unknown properties mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return mapper; }
From source file:de.learnlib.alex.plugin.TestSuiteGeneratorMojo.java
@Override public void execute() throws MojoExecutionException { final ObjectMapper mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); final TestSuite export; try {/*from w w w . ja v a 2s. c o m*/ export = mapper.readValue(sourceFile, TestSuite.class); } catch (IOException e) { throw new MojoExecutionException("Error reading export file", e); } writeAbstractSuperClass(export); final List<TestCase> testCases = export.getTestCases(); for (int i = 0; i < testCases.size(); i++) { writeTestCase(testCases.get(i), i); } writeTestSuiteConfiguration(export); }
From source file:org.openmhealth.dsu.configuration.JacksonConfiguration.java
@Bean public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); // serialise timestamps in an ISO8601 textual representation objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // serialise keys in snake_case objectMapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy()); return objectMapper; }
From source file:com.frank.search.solr.core.schema.SolrSchemaWriter.java
SchemaDefinition loadExistingSchema(String collectionName) { try {/*from ww w . j a va 2 s .c o m*/ SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrClient(collectionName)); if (response != null && response.getNode("schema") != null) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.AUTO_DETECT_CREATORS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class); } return null; } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e); } catch (SolrException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } }
From source file:org.springframework.data.solr.core.schema.SolrSchemaWriter.java
SchemaDefinition loadExistingSchema(String collectionName) { try {//from w ww .j av a 2 s . com SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrServer(collectionName)); if (response != null && response.getNode("schema") != null) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.AUTO_DETECT_CREATORS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class); } return null; } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e); } catch (SolrException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } }
From source file:org.openscoring.service.ObjectMapperProvider.java
public ObjectMapperProvider() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new OpenscoringModule()); mapper.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); setMapper(mapper);//from ww w . j av a 2s.c o m }
From source file:com.proofpoint.json.ObjectMapperProvider.java
@Override public ObjectMapper get() { ObjectMapper objectMapper = new ObjectMapper(); // ignore unknown fields (for backwards compatibility) objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // use ISO dates objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // skip fields that are null instead of writing an explicit json null value objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // disable auto detection of json properties... all properties must be explicit objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS); objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS); objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); objectMapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS); objectMapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS); if (jsonSerializers != null || jsonDeserializers != null || keySerializers != null || keyDeserializers != null) { SimpleModule module = new SimpleModule(getClass().getName(), new Version(1, 0, 0, null, null, null)); if (jsonSerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : jsonSerializers.entrySet()) { addSerializer(module, entry.getKey(), entry.getValue()); }/*w ww .j a v a2s .c o m*/ } if (jsonDeserializers != null) { for (Entry<Class<?>, JsonDeserializer<?>> entry : jsonDeserializers.entrySet()) { addDeserializer(module, entry.getKey(), entry.getValue()); } } if (keySerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : keySerializers.entrySet()) { addKeySerializer(module, entry.getKey(), entry.getValue()); } } if (keyDeserializers != null) { for (Entry<Class<?>, KeyDeserializer> entry : keyDeserializers.entrySet()) { module.addKeyDeserializer(entry.getKey(), entry.getValue()); } } modules.add(module); } for (Module module : modules) { objectMapper.registerModule(module); } return objectMapper; }
From source file:io.airlift.json.ObjectMapperProvider.java
@Override public ObjectMapper get() { ObjectMapper objectMapper = new ObjectMapper(); // ignore unknown fields (for backwards compatibility) objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // use ISO dates objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // skip fields that are null instead of writing an explicit json null value objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // disable auto detection of json properties... all properties must be explicit objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS); objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS); objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS); objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); objectMapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS); if (jsonSerializers != null || jsonDeserializers != null || keySerializers != null || keyDeserializers != null) { SimpleModule module = new SimpleModule(getClass().getName(), new Version(1, 0, 0, null)); if (jsonSerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : jsonSerializers.entrySet()) { addSerializer(module, entry.getKey(), entry.getValue()); }/*from w w w . j a v a 2 s. c o m*/ } if (jsonDeserializers != null) { for (Entry<Class<?>, JsonDeserializer<?>> entry : jsonDeserializers.entrySet()) { addDeserializer(module, entry.getKey(), entry.getValue()); } } if (keySerializers != null) { for (Entry<Class<?>, JsonSerializer<?>> entry : keySerializers.entrySet()) { addKeySerializer(module, entry.getKey(), entry.getValue()); } } if (keyDeserializers != null) { for (Entry<Class<?>, KeyDeserializer> entry : keyDeserializers.entrySet()) { module.addKeyDeserializer(entry.getKey(), entry.getValue()); } } modules.add(module); } for (Module module : modules) { objectMapper.registerModule(module); } return objectMapper; }
From source file:org.killbill.billing.server.listeners.KillbillPlatformGuiceListener.java
protected JaxrsJacksonModule getJacksonModule() { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JodaModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return new JaxrsJacksonModule(objectMapper); }
From source file:com.nonninz.robomodel.RoboManager.java
public T create(String json) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.USE_ANNOTATIONS, true); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); try {/* www.jav a2 s .com*/ final T result = mapper.readValue(json, mKlass); result.setContext(mContext); return result; } catch (Exception e) { throw new JsonException("Error while parsing JSON", e); } }