List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
From source file:org.moserp.common.rest.ObjectMapperCustomizer.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (!(bean instanceof ObjectMapper)) { return bean; }//from w w w . j a v a 2s. c o m ObjectMapper mapper = (ObjectMapper) bean; mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); registerQuantitySerializer(mapper); mapper.registerModules(new MoneyModule(), new JavaTimeModule(), new Jackson2HalModule()); return mapper; }
From source file:com.feedeo.rest.client.AbstractRestClient.java
protected ObjectMapper createObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(WRITE_DATES_AS_TIMESTAMPS, true); objectMapper.configure(WRITE_ENUMS_USING_TO_STRING, true); objectMapper.configure(READ_ENUMS_USING_TO_STRING, true); objectMapper.registerModule(new JodaModule()); objectMapper.setTimeZone(getDefault()); return objectMapper; }
From source file:org.springframework.social.wunderlist.api.impl.WunderlistTemplate.java
@Override protected MappingJackson2HttpMessageConverter getJsonMessageConverter() { MappingJackson2HttpMessageConverter converter = super.getJsonMessageConverter(); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new WunderlistModule()); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); converter.setObjectMapper(mapper);/* w w w . ja v a 2 s. c om*/ return converter; }
From source file:com.github.fge.jackson.JsonNodeReader.java
public JsonNodeReader(final ObjectMapper mapper) { reader = mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true).reader(JsonNode.class); }
From source file:net.jawr.web.resource.bundle.factory.util.JsonPropertiesSource.java
@Override protected void loadConfig(Properties props, String path, InputStream is) { try {//from w w w . jav a2 s .c o m // load properties into a Properties object String jsonContent = IOUtils.toString(is); // create an ObjectMapper instance. ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); // use the ObjectMapper to read the json string and create a tree JsonNode node = mapper.readTree(jsonContent); generateProperties(node, null, props); } catch (JsonParseException e) { throw new BundlingProcessException( "jawr configuration could not be loaded at " + path + FIELD_NAME_SEPARATOR, e); } catch (IOException e) { throw new BundlingProcessException( "jawr configuration could not be loaded at " + path + FIELD_NAME_SEPARATOR, e); } }
From source file:it.tai.solr.http.HttpInvoker.java
public SolrResponse getSolrReport(REPORT_ACTION action) throws IOException, UnsupportedActionException { String url;/* w w w. java 2s .c o m*/ switch (action) { case SUMMARY: url = solrURL + "action=" + REPORT_ACTION.SUMMARY.getCode() + "&wt=json"; break; case REPORT: url = solrURL + "action=" + REPORT_ACTION.REPORT.getCode() + "&wt=json"; break; default: throw new UnsupportedActionException("Unsupported report action"); } CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpGet httpget = new HttpGet(url); logger.info("Excuting SOLR report request: " + httpget.getRequestLine()); long currTime = System.currentTimeMillis(); CloseableHttpResponse response = httpclient.execute(httpget); responseTime("SOLR report ", currTime); checkResponse(response); String data = EntityUtils.toString(response.getEntity()); if (logger.isDebugEnabled()) { logger.debug("Response data \n" + data); } ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true); JsonNode root = mapper.readTree(data).path("Summary").path("alfresco").path("Searcher"); SolrResponse toReturn = mapper.readValue(root.traverse(), SolrResponse.class); toReturn.setRawResponse(data); toReturn.setUrl(httpget.getRequestLine().getUri()); return toReturn; } finally { httpclient.close(); } }
From source file:de.brendamour.jpasskit.signing.PKAbstractSIgningUtil.java
protected ObjectWriter configureObjectMapper(final ObjectMapper jsonObjectMapper) { jsonObjectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); jsonObjectMapper.setDateFormat(new ISO8601DateFormat()); SimpleFilterProvider filters = new SimpleFilterProvider(); // haven't found out, how to stack filters. Copying the validation one for now. filters.addFilter("validateFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors")); filters.addFilter("pkPassFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors", "foregroundColorAsObject", "backgroundColorAsObject", "labelColorAsObject", "passThatWasSet")); filters.addFilter("barcodeFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors", "messageEncodingAsString")); filters.addFilter("charsetFilter", SimpleBeanPropertyFilter.filterOutAllExcept("name")); jsonObjectMapper.setSerializationInclusion(Include.NON_NULL); jsonObjectMapper.addMixIn(Object.class, ValidateFilterMixIn.class); jsonObjectMapper.addMixIn(PKPass.class, PkPassFilterMixIn.class); jsonObjectMapper.addMixIn(PKBarcode.class, BarcodeFilterMixIn.class); jsonObjectMapper.addMixIn(Charset.class, CharsetFilterMixIn.class); return jsonObjectMapper.writer(filters); }
From source file:com.microsoft.rest.serializer.JacksonMapperAdapter.java
/** * Initializes an instance of JacksonMapperAdapter with default configurations * applied to the object mapper./*from w ww . ja va2s.c o m*/ * * @param mapper the object mapper to use. */ protected void initializeObjectMapper(ObjectMapper mapper) { mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) .setSerializationInclusion(JsonInclude.Include.NON_NULL).registerModule(new JodaModule()) .registerModule(ByteArraySerializer.getModule()).registerModule(DateTimeSerializer.getModule()) .registerModule(DateTimeRfc1123Serializer.getModule()) .registerModule(HeadersSerializer.getModule()); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); }
From source file:mobi.designmyapp.template.sample.upvprod.task.PoiProxyRequestTask.java
/** * Retrieves the PoiProxy data and processes mapping of the JSON response to a PoiProxyResult POJO * @param url should contain the url call to PoiProxy services * @return//www .ja va 2 s. c o m */ @Override protected PoiProxyResult doInBackground(URI... url) { PoiProxyResult result = null; HttpClient client = new DefaultHttpClient(); //For each URI provided, we call and get the result for (URI callURI : url) { // Process http request try { HttpGet request = new HttpGet(callURI); HttpResponse response = client.execute(request); StatusLine statusLine = response.getStatusLine(); // If request has returned correctly, process JSON if (statusLine.getStatusCode() == HttpStatus.SC_OK) { InputStream resultStream = response.getEntity().getContent(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); // If first call, the result is the object if (result == null) result = mapper.readValue(resultStream, PoiProxyResult.class); // Otherwise, add the results to the previous result else result.getFeatures() .addAll(mapper.readValue(resultStream, PoiProxyResult.class).getFeatures()); resultStream.close(); } else { //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (IOException e) { Log.e(TAG, "Error while retrieving POI Proxy query: " + callURI + " data:" + e); } } if (result != null) Collections.shuffle(result.getFeatures()); return result; }
From source file:org.opendaylight.groupbasedpolicy.jsonrpc.RpcServer.java
void handleNewConnection(String identifier, Channel newChannel) throws InterruptedException, ExecutionException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonRpcEndpoint endpoint = new JsonRpcEndpoint(identifier, connectionService, objectMapper, newChannel, messageMap, broker);//from ww w .j a va 2s. c o m endpoint.setContext(context); JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(endpoint); newChannel.pipeline().addLast(binderHandler); connectionService.addConnection(endpoint); ChannelFuture closeFuture = newChannel.closeFuture(); closeFuture.addListener(endpoint); }