List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure
public ObjectMapper configure(JsonGenerator.Feature f, boolean state)
From source file:com.hp.autonomy.iod.client.converter.IodConverter.java
/** * Creates a new IodConverter/*from w w w .ja va 2s .c o m*/ * * @param objectMapper Jackson ObjectMapper for handling Json */ public IodConverter(final ObjectMapper objectMapper) { final ObjectMapper objectMapperCopy = objectMapper.copy(); // HPE Haven OnDemand does not consider adding new properties to be a breaking change, so ignore any unknown properties objectMapperCopy.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); converter = new JacksonConverter(objectMapperCopy); }
From source file:com.netflix.conductor.client.http.ClientBase.java
protected ObjectMapper objectMapper() { final ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); om.setSerializationInclusion(Include.NON_NULL); om.setSerializationInclusion(Include.NON_EMPTY); return om;//from w w w .java 2 s . c o m }
From source file:nl.knaw.huygens.security.server.ObjectMapperProvider.java
@Override public ObjectMapper getContext(Class<?> type) { ObjectMapper objectMapper = new ObjectMapper(); log.debug("Setting up Jackson ObjectMapper: [{}]", objectMapper); // These are 'dev' settings giving us human readable output. objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // JodaModule maps DateTime to a flat String (or timestamp, see above) instead of recursively yielding // the entire object hierarchy of DateTime which is way too verbose. objectMapper.registerModule(new JodaModule()); return objectMapper; }
From source file:springfox.documentation.swagger2.configuration.Swagger2JacksonModule.java
public void maybeRegisterModule(ObjectMapper objectMapper) { if (objectMapper.findMixInClassFor(Swagger.class) == null) { objectMapper.registerModule(new Swagger2JacksonModule()); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); }//from w w w . j a v a 2s .c o m }
From source file:com.jaspersoft.jasperserver.remote.settings.DateTimeSettingsProvider.java
private Map<String, Object> convertToJSONObject(String jsonAsString) { try {//from ww w . j a va 2 s .c om ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); return mapper.readValue(jsonAsString, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { throw new RuntimeException("Error during parsing JSON. Invalid content" + jsonAsString); } }
From source file:com.servioticy.api.commons.utils.JacksonJsonProvider.java
public JacksonJsonProvider() { if (commonMapper == null) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(Visibility.ANY)); commonMapper = mapper;/*w w w.j a v a 2s . co m*/ } super.setMapper(commonMapper); }
From source file:fr.ortolang.diffusion.runtime.engine.task.ImportHandlesTask.java
@Override public void executeTask(DelegateExecution execution) throws RuntimeEngineTaskException { checkParameters(execution);//from w ww.j a va 2 s . c om String handlespath = execution.getVariable(HANDLES_PATH_PARAM_NAME, String.class); if (execution.getVariable(INITIER_PARAM_NAME, String.class) .equals(MembershipService.SUPERUSER_IDENTIFIER)) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); try { if (getUserTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) { LOGGER.log(Level.FINE, "starting new user transaction."); getUserTransaction().begin(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "unable to start new user transaction", e); } try { boolean needcommit; long tscommit = System.currentTimeMillis(); List<JsonHandle> handles = Arrays .asList(mapper.readValue(new File(handlespath), JsonHandle[].class)); LOGGER.log(Level.FINE, "- starting import handles"); boolean partial = false; StringBuilder report = new StringBuilder(); for (JsonHandle handle : handles) { needcommit = false; try { getHandleStore().recordHandle(handle.handle, handle.key, handle.url); } catch (HandleStoreServiceException e) { partial = true; report.append("unable to import handle [").append(handle.handle).append("] : ") .append(e.getMessage()).append("\r\n"); } if (System.currentTimeMillis() - tscommit > 30000) { LOGGER.log(Level.FINE, "current transaction exceed 30sec, need commit."); needcommit = true; } try { if (needcommit && getUserTransaction().getStatus() == Status.STATUS_ACTIVE) { LOGGER.log(Level.FINE, "committing active user transaction."); getUserTransaction().commit(); tscommit = System.currentTimeMillis(); getUserTransaction().begin(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "unable to commit active user transaction", e); } } if (partial) { throwRuntimeEngineEvent( RuntimeEngineEvent.createProcessLogEvent(execution.getProcessBusinessKey(), "Some handles has not been imported (see trace for detail)")); throwRuntimeEngineEvent(RuntimeEngineEvent .createProcessTraceEvent(execution.getProcessBusinessKey(), report.toString(), null)); } throwRuntimeEngineEvent(RuntimeEngineEvent.createProcessLogEvent(execution.getProcessBusinessKey(), "Import Handles done")); } catch (IOException e) { throw new RuntimeEngineTaskException("error parsing json file: " + e.getMessage()); } } else { throw new RuntimeEngineTaskException( "only " + MembershipService.SUPERUSER_IDENTIFIER + " can perform this task !!"); } }
From source file:com.wordnik.swagger.jaxrs.json.JacksonJsonProvider.java
public JacksonJsonProvider() { if (commonMapper == null) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); commonMapper = mapper;/* w w w .j ava 2 s.c o m*/ } super.setMapper(commonMapper); }
From source file:org.apache.marmotta.client.clients.LDPathClient.java
/** * Evaluate the path query passed as second argument, starting at the resource with the uri given as first argument. * Returns a List of RDFNode objects.//from w w w . j a v a2s . co m * * * @param uri the uri of the resource where to start the path evaluation * @param path the path to evaluate * @return a list of RDFNodes representing the result of the path evaluation as returned by the server * @throws MarmottaClientException * @throws IOException */ public List<RDFNode> evaluatePath(String uri, String path) throws MarmottaClientException, IOException { HttpClient httpClient = HTTPUtil.createClient(config); String serviceUrl = config.getMarmottaUri() + URL_PATH_SERVICE + "?path=" + URLEncoder.encode(path, "utf-8") + "&uri=" + URLEncoder.encode(uri, "utf-8"); HttpGet get = new HttpGet(serviceUrl); get.setHeader("Accept", "application/json"); try { HttpResponse response = httpClient.execute(get); switch (response.getStatusLine().getStatusCode()) { case 200: log.debug("LDPath Path Query {} evaluated successfully", path); ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); List<Map<String, String>> serverResult = mapper.readValue(response.getEntity().getContent(), new TypeReference<List<Map<String, String>>>() { }); List<RDFNode> result = new ArrayList<RDFNode>(); for (Map<String, String> value : serverResult) { result.add(RDFJSONParser.parseRDFJSONNode(value)); } return result; case 400: log.error("the server did not accept the uri ({}) or path ({}) arguments", uri, path); throw new ContentFormatException( "the server did not accept the uri (" + uri + ") or path (" + path + ") arguments"); case 404: log.error("the resource with URI {} does not exist on the server", uri); throw new NotFoundException("the resource with URI " + uri + " does not exist on the server"); default: log.error("error evaluating LDPath Path Query {}: {} {}", new Object[] { path, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase() }); throw new MarmottaClientException("error evaluating LDPath Path Query " + path + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); } } finally { get.releaseConnection(); } }
From source file:cn.org.once.cstack.volumes.VolumeControllerTestIT.java
private String getString(VolumeResource volumeResource, ObjectMapper mapper) throws JsonProcessingException { mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter(); return ow.writeValueAsString(volumeResource); }