List of usage examples for com.fasterxml.jackson.databind ObjectMapper enable
public ObjectMapper enable(SerializationFeature f)
From source file:it.uniroma2.sag.kelp.linearization.nystrom.NystromMethodEnsemble.java
/** * Save an Ensemble of Nystrom projectors on file. * /*from w w w . ja v a 2s . c o m*/ * @param outputFilePath * The output file name * @throws FileNotFoundException * @throws IOException */ public void save(String outputFilePath) throws FileNotFoundException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); OutputStream outputStream = FileUtils.createOutputStream(outputFilePath); mapper.writeValue(outputStream, this); }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Creates all defined Json schemas based on the provided set of package names * and options and add the schemas to the specified map. * * @author paouelle//from w ww . java 2 s. c o m * * @param pkgs the set of packages to create Json schemas for * @param suffixes the map of provided suffix values * @param matching whether or not to only create schemas for keyspaces that * matches the specified set of suffixes * @param schemas the map where to record the Json schema for the pojo classes * found * @throws LinkageError if the linkage fails for one of the specified entity * class * @throws ExceptionInInitializerError if the initialization provoked by one * of the specified entity class fails * @throws IllegalArgumentException if no pojos are found in any of the * specified packages * @throws IOException if an I/O error occurs while generating the Json schemas */ private static void createJsonSchemasFromPackages(String[] pkgs, Map<String, String> suffixes, boolean matching, Map<Class<?>, JsonSchema> schemas) throws IOException { for (final String pkg : pkgs) { if (pkg == null) { continue; } final CreateSchemas cs = (matching ? StatementBuilder.createMatchingSchemas(pkg) : StatementBuilder.createSchemas(pkg)); // pass all suffixes for (final Map.Entry<String, String> e : suffixes.entrySet()) { // register the suffix value with the corresponding suffix type cs.where(StatementBuilder.eq(e.getKey(), e.getValue())); } for (final Class<?> c : cs.getObjectClasses()) { System.out.println(Tool.class.getSimpleName() + ": creating Json schema for " + c.getName()); final ObjectMapper m = new ObjectMapper(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.registerModule(new Jdk8Module()); m.enable(SerializationFeature.INDENT_OUTPUT); m.acceptJsonFormatVisitor(m.constructType(c), visitor); schemas.put(c, visitor.finalSchema()); } } }
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);/* ww w . j a va 2 s . com*/ }
From source file:org.dswarm.graph.gdm.test.BaseGDMResourceTest.java
protected void readGDMFromDB(final String recordClassURI, final String dataModelURI, final int numberOfStatements, final Optional<Integer> optionalAtMost) throws IOException { final ObjectMapper objectMapper = Util.getJSONObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); final ObjectNode requestJson = objectMapper.createObjectNode(); requestJson.put(DMPStatics.RECORD_CLASS_URI_IDENTIFIER, recordClassURI); requestJson.put(DMPStatics.DATA_MODEL_URI_IDENTIFIER, dataModelURI); if (optionalAtMost.isPresent()) { requestJson.put(DMPStatics.AT_MOST_IDENTIFIER, optionalAtMost.get()); }/*from w ww. java 2 s. c om*/ final String requestJsonString = objectMapper.writeValueAsString(requestJson); // POST the request final ClientResponse response = target().path("/get").type(MediaType.APPLICATION_JSON_TYPE) .accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, requestJsonString); Assert.assertEquals("expected 200", 200, response.getStatus()); final InputStream actualResult = response.getEntity(InputStream.class); final BufferedInputStream bis = new BufferedInputStream(actualResult, 1024); final ModelParser modelParser = new ModelParser(bis); final org.dswarm.graph.json.Model model = new org.dswarm.graph.json.Model(); final Observable<Void> parseObservable = modelParser.parse().map(resource1 -> { model.addResource(resource1); return null; }); parseObservable.toBlocking().lastOrDefault(null); bis.close(); actualResult.close(); LOG.debug("read '{}' statements", model.size()); Assert.assertEquals("the number of statements should be " + numberOfStatements, numberOfStatements, model.size()); }
From source file:synapticloop.getcookie.api.GetCookieApiClient.java
private ObjectMapper initializeObjectMapperJson() { ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT); mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS); return mapper; }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Creates all defined Json schemas based on the provided set of class names * and options and add the schemas to the specified map. For each class found; * the corresponding array element will be nulled. All others are simply * skipped.//from w w w .ja va2 s . co m * * @author paouelle * * @param cnames the set of class names to create Json schemas for * @param suffixes the map of provided suffix values * @param matching whether or not to only create schemas for keyspaces that * matches the specified set of suffixes * @param schemas the map where to record the Json schema for the pojo classes * found * @throws LinkageError if the linkage fails for one of the specified entity * class * @throws ExceptionInInitializerError if the initialization provoked by one * of the specified entity class fails * @throws IOException if an I/O error occurs while generating the Json schemas */ private static void createJsonSchemasFromClasses(String[] cnames, Map<String, String> suffixes, boolean matching, Map<Class<?>, JsonSchema> schemas) throws IOException { next_class: for (int i = 0; i < cnames.length; i++) { try { final Class<?> clazz = Class.forName(cnames[i]); cnames[i] = null; // clear since we found a class final CreateSchema<?> cs = StatementBuilder.createSchema(clazz); // pass all required suffixes for (final Map.Entry<String, String> e : suffixes.entrySet()) { // check if this suffix type is defined final FieldInfo<?> suffix = cs.getClassInfo().getSuffixKeyByType(e.getKey()); if (suffix != null) { // register the suffix value with the corresponding suffix name cs.where(StatementBuilder.eq(suffix.getSuffixKeyName(), e.getValue())); } else if (matching) { // we have one more suffix then defined with this pojo // and we were requested to only do does that match the provided // suffixes so skip the class continue next_class; } } for (final Class<?> c : cs.getObjectClasses()) { System.out.println(Tool.class.getSimpleName() + ": creating Json schema for " + c.getName()); final ObjectMapper m = new ObjectMapper(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.registerModule(new Jdk8Module()); m.enable(SerializationFeature.INDENT_OUTPUT); m.acceptJsonFormatVisitor(m.constructType(c), visitor); schemas.put(c, visitor.finalSchema()); } } catch (ClassNotFoundException e) { // ignore and continue } } }
From source file:com.fitbur.docker.client.internal.ObjectMapperProvider.java
@PerLookup @Override//from www. j ava2 s. c om public ObjectMapper provide() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(MapperFeature.USE_ANNOTATIONS).enable(MapperFeature.AUTO_DETECT_GETTERS) .enable(MapperFeature.AUTO_DETECT_SETTERS).enable(MapperFeature.AUTO_DETECT_IS_GETTERS) .enable(MapperFeature.AUTO_DETECT_FIELDS).enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS); mapper.disable(SerializationFeature.INDENT_OUTPUT).enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true) .configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true); return mapper; }
From source file:net.proest.librepilot.web.handler.ObjectHandler.java
public void handleGet(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); List<String> targetObjects = Arrays.asList(target.split("/")); SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>(); for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) { if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) { if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) { mFcDevice.requestObject(xmlObj.getName()); objects.put(xmlObj.getName(), xmlObj); }/* ww w .ja v a2s .co m*/ } } SortedMap<String, UAVTalkObjectSerializer> uavObjects = new TreeMap<>(); for (UAVTalkXMLObject xmlObj : objects.values()) { UAVTalkObjectSerializer os = new UAVTalkObjectSerializer(); if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) { UAVTalkObject obj = mFcDevice.getObjectTree().getObjectFromName(xmlObj.getName()); for (int i = 0; i < obj.getInstances().values().size(); i++) { UAVTalkInstanceSerializer is = new UAVTalkInstanceSerializer(); for (UAVTalkXMLObject.UAVTalkXMLObjectField xmlField : xmlObj.getFields().values()) { UAVTalkFieldSerializer fs = new UAVTalkFieldSerializer(); boolean hasElements = true; Object res = null; for (String element : xmlField.getElements()) { try { res = mFcDevice.getObjectTree().getData(xmlObj.getName(), i, xmlField.getName(), element); if (element == null || xmlField.getElements().size() == 1 && (element.equals("") || element.equals("0"))) { hasElements = false; fs.setElements(null); fs.setValue(res); } else { fs.getElements().put(element, res); fs.setValue(null); } } catch (UAVTalkMissingObjectException e) { e.printStackTrace(); } } if (hasElements) { is.getFields().put(xmlField.getName(), fs); } else { is.getFields().put(xmlField.getName(), res); } } os.getInstances().put(i, is); } } uavObjects.put(xmlObj.getName(), os); } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } String callback = request.getParameter("callback"); if (callback != null) { response.setContentType("application/javascript"); out.println(callback + "("); } else { response.setContentType("application/json"); } ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); out.println(mapper.writeValueAsString(uavObjects)); if (callback != null) { out.print(")"); } out.println(""); }
From source file:org.axiom_tools.codecs.ModelCodec.java
/** * Returns a new JSON object mapper./*from w ww.j av a 2s. c o m*/ */ private ObjectMapper buildObjectMapper() { ObjectMapper result = new ObjectMapper(); result.setAnnotationIntrospector(new JaxbAnnotationIntrospector(result.getTypeFactory())); result.enable(SerializationFeature.INDENT_OUTPUT); return result; }