List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
From source file:com.example.common.MoneyJacksonAutoConfiguration.java
public CustomPojoToJsonMessageConverter(ObjectMapper mapper) { super(MimeTypeUtils.APPLICATION_JSON); this.mapper = mapper; mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.registerModule(new JodaMoneyModule()); }
From source file:biz.dfch.j.clickatell.ClickatellClient.java
public CoverageResponse getCoverage(@NotNullable String recipient) throws URISyntaxException, IOException { URI uriCoverage = new URI(String.format(APICOVERAGE, recipient)); String response = Request.Get(uriCoverage.toString()).setHeader(headerApiVersion) .setHeader(headerContentType).setHeader(headerAccept).setHeader("Authorization", bearerToken) .execute().returnContent().asString(); ObjectMapper om = new ObjectMapper(); om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); CoverageResponse coverageResponse = om.readValue(response, CoverageResponse.class); return coverageResponse; }
From source file:logfile.LogfileStreamer.java
public void run() throws Exception { startElasticsearchIfNecessary();/* ww w .ja va 2 s . com*/ createIndexAndMappingIfNecessary(); // index into the metrics index without date formatting ElasticsearchReporter reporter = ElasticsearchReporter.forRegistry(registry).hosts("localhost:9200") .indexDateFormat("").percolationNotifier(new HttpNotifier()).percolationFilter(MetricFilter.ALL) .build(); reporter.start(60, TimeUnit.SECONDS); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); ObjectReader reader = objectMapper.reader(Map.class); MappingIterator<Map<String, Object>> iterator = reader.readValues(getInputStream()); try { while (iterator.hasNextValue()) { Map<String, Object> entry = iterator.nextValue(); if (entry.containsKey("_heartbeat_")) { heartbeatCounter.inc(); continue; } if (entry.containsKey("ll") && entry.containsKey("t")) { long timestamp = ((Integer) entry.get("t")).longValue(); List<Number> location = (List<Number>) entry.get("ll"); double latitude = location.get(0).doubleValue(); double longitude = location.get(1).doubleValue(); addToBulkRequest(timestamp, latitude, longitude); entryMeter.mark(1); } } } finally { executeBulkRequest(); } }
From source file:com.cloudera.nav.sdk.examples.lineage3.LineageExport.java
@SuppressWarnings("unchecked") private void fetchAndWriteLineage(Set<String> entityIds, FileWriter fw, ClientConfig config) throws IOException { HttpURLConnection connection = createHttpConnection(config, entityIds); try {/*from w w w . j av a 2s . c o m*/ InputStream stream = connection.getInputStream(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); Collection<Map<String, Object>> entities = mapper.readValue(stream, new TypeReference<Collection<Map<String, Object>>>() { }); for (Map<String, Object> m : entities) { String id = (String) m.get("id"); Map<String, Object> children = (Map<String, Object>) m.get("children"); if (children != null) { Collection<String> childrenIds; for (Map.Entry<String, Object> entry : children.entrySet()) { childrenIds = (Collection<String>) entry.getValue(); for (String childId : childrenIds) { fw.write(String.format("%s, %s, %s%n", id, childId, entry.getKey())); } } } } } catch (IOException ioe) { Throwables.propagate(ioe); } finally { IOUtils.close(connection); } }
From source file:org.efaps.rest.AbstractRest.java
/** * Gets the JSON reply./* w w w .ja va 2 s .com*/ * * @param _jsonObject the _json object * @return the JSON reply * @throws JsonProcessingException the json processing exception */ protected String getJSONReply(final Object _jsonObject) { String ret = ""; final ObjectMapper mapper = new ObjectMapper(); if (LOG.isDebugEnabled()) { mapper.enable(SerializationFeature.INDENT_OUTPUT); } mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.registerModule(new JodaModule()); try { ret = mapper.writeValueAsString(_jsonObject); } catch (final JsonProcessingException e) { LOG.error("Catched JsonProcessingException", e); } return ret; }
From source file:com.logsniffer.app.CoreAppConfig.java
@Bean public ObjectMapper jsonObjectMapper() { final ObjectMapper jsonMapper = new ObjectMapper(); jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true); jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion()); module.setSerializerModifier(new BeanSerializerModifier() { @Override//from w w w. j av a 2 s . c o m public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType, final BeanDescription beanDesc, final JsonSerializer<?> serializer) { if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) { return new FieldsMapMixInLikeSerializer(); } else { return super.modifyMapSerializer(config, valueType, beanDesc, serializer); } } }); jsonMapper.registerModule(module); return jsonMapper; }
From source file:net.aethersanctum.lilrest.server.JaxRsServerModule.java
public ObjectMapper customMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModules(new Jdk8Module(), new JSR310Module()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
From source file:springfox.documentation.swagger1.configuration.SwaggerJacksonModule.java
public void maybeRegisterModule(ObjectMapper objectMapper) { if (isModuleSetup(objectMapper)) { objectMapper.registerModule(new SwaggerJacksonModule()); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); }/*from w w w .j a v a2s . c o m*/ }
From source file:retrofit.JacksonConverterFactoryTest.java
@Before public void setUp() { SimpleModule module = new SimpleModule(); module.addSerializer(AnInterface.class, new AnInterfaceSerializer()); module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module);/*from w w w.jav a 2s.co m*/ mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")) .addConverterFactory(JacksonConverterFactory.create(mapper)).build(); service = retrofit.create(Service.class); }
From source file:uk.co.flax.biosolr.ontology.documents.storage.elasticsearch.ESStorageEngine.java
/** * Get an object mapper for serializing the product data. * @return the object mapper./*from ww w. ja va2s . c o m*/ */ private ObjectMapper getSerializationMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); return mapper; }