List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace
public void printStackTrace()
From source file:curly.artifactory.ArtifactoryTestHelper.java
public static Artifact createArtifact(MongoTemplate mongoTemplate) { mongoTemplate.findAllAndRemove(new Query(), Artifact.class); Artifact artifact = new Artifact(); Set<Language> languages = new HashSet<>(0); Set<Tag> tags = new HashSet<>(0); tags.add(new Tag("document")); tags.add(new Tag("nosql")); languages.add(new Language("java")); languages.add(new Language("groovy")); languages.add(new Language("ruby")); languages.add(new Language("scala")); languages.add(new Language("javascript")); artifact.setName("curly"); artifact.setDescription("a hobby project"); artifact.setAuthor("joaoevangelista"); artifact.setCategory(new Category("database")); artifact.setHomePage("http://example.com"); artifact.setIncubation(LocalDate.now().toString()); artifact.setLanguages(languages);//from w w w .j a va 2 s . co m artifact.setTags(tags); artifact.setOwner("6969"); mongoTemplate.insert(artifact); Assert.assertTrue(artifact.getId() != null); try { System.out.println(new ObjectMapper().writeValueAsString(artifact)); } catch (JsonProcessingException e) { e.printStackTrace(); } return artifact; }
From source file:de.elanev.studip.android.app.backend.datamodel.Settings.java
public static Settings fromJson(String jsonString) { ObjectMapper mapper = new ObjectMapper(); Settings settings = null;//from w ww .j av a2s . c om try { settings = mapper.readValue(jsonString, Settings.class); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return settings; }
From source file:edu.brandeis.cs.json.JsonProxy.java
public static String obj2json(Object obj) throws Exception { ObjectWriter ow = new ObjectMapper().writer(); String json = null;/*from w ww . j a v a 2 s . c o m*/ try { json = ow.writeValueAsString(obj); } catch (JsonProcessingException e) { e.printStackTrace(); throw new Exception(e); } return json; }
From source file:org.pad.pgsql.loadmovies.LoadFiles.java
/** * Load ratings and enrich movies with tags informations before updating the related movie. * * @throws Exception/*w ww . jav a 2 s .co m*/ */ private static void loadRatings() throws Exception { //MultivalueMap with key movieId and values all tags LinkedMultiValueMap<Integer, Tag> tags = readTags(); //MultivalueMap with key movieId and values all ratings LinkedMultiValueMap<Integer, Rating> ratings = new LinkedMultiValueMap(); //"userId,movieId,rating,timestamp final Reader reader = new FileReader("C:\\PRIVE\\SRC\\ml-20m\\ratings.csv"); CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader()); RatingDao ratingDao = new RatingDao(DS); for (CSVRecord record : parser) { Integer movieId = Integer.parseInt(record.get("movieId")); Integer userId = Integer.parseInt(record.get("userId")); if (keepId(movieId) && keepId(userId)) { //Building a rating object. Rating rating = new Rating(); rating.setUserId(userId); rating.setMovieId(movieId); rating.setRating(Float.parseFloat(record.get("rating"))); rating.setDate(new Date(Long.parseLong(record.get("timestamp")) * 1000)); //Add for json saving ratings.add(rating.getMovieId(), rating); //traditional saving //ratingDao.save(rating); } } MovieDaoJSON movieDaoJSON = new MovieDaoJSON(DS); ratings.entrySet().stream().forEach((integerListEntry -> { //Building other information objects OtherInformations otherInformations = new OtherInformations(); List ratingList = integerListEntry.getValue(); otherInformations.setRatings(ratingList.subList(0, Math.min(10, ratingList.size()))); otherInformations.computeMean(); //Retrieve tags from the movieId otherInformations.setTags(tags.get(integerListEntry.getKey())); try { movieDaoJSON.addOtherInformationsToMovie(integerListEntry.getKey(), otherInformations); } catch (JsonProcessingException e) { e.printStackTrace(); } })); }
From source file:org.opendatakit.common.android.utilities.NameUtil.java
public static String normalizeDisplayName(String displayName) { if ((displayName.startsWith("\"") && displayName.endsWith("\"")) || (displayName.startsWith("{") && displayName.endsWith("}"))) { return displayName; } else {// w ww .j a v a2 s . c om try { return ODKFileUtils.mapper.writeValueAsString(displayName); } catch (JsonProcessingException e) { e.printStackTrace(); throw new IllegalArgumentException("normalizeDisplayName: Invalid displayName " + displayName); } } }
From source file:us.colloquy.util.ElasticLoader.java
public static void uploadLettersToElasticServer(Properties properties, List<Letter> letterList) { if (letterList.size() > 0) { try (RestHighLevelClient client = new RestHighLevelClient(RestClient .builder(new HttpHost("localhost", 9200, "http"), new HttpHost("localhost", 9201, "http")))) { BulkRequest request = new BulkRequest(); ObjectMapper ow = new ObjectMapper(); // create once, reuse ow.enable(SerializationFeature.INDENT_OUTPUT); for (Letter letter : letterList) { try { String json = ow.writerWithDefaultPrettyPrinter().writeValueAsString(letter); String name = "unk"; if (letter.getTo().size() > 0) { name = letter.getTo().get(0).getLastName(); }//from ww w . ja v a 2 s . c om String id = letter.getId() + "-" + letter.getDate() + "-" + letter.getSource(); if (StringUtils.isNotEmpty(json)) { IndexRequest indexRequest = new IndexRequest("lntolstoy-letters", "letters", id) .source(json, XContentType.JSON); request.add(new UpdateRequest("lntolstoy-letters", "letters", id) .doc(json, XContentType.JSON).upsert(indexRequest)); } else { System.out.println("empty doc: " + id.toString()); } } catch (JsonProcessingException e) { e.printStackTrace(); } } BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); if (bulkResponse.hasFailures()) // process failures by iterating through each bulk response item { System.err.println(bulkResponse.buildFailureMessage()); for (BulkItemResponse b : bulkResponse) { System.out.println("Error inserting id: " + b.getId()); System.out.println("Failure message: " + b.getFailureMessage()); } } else { System.out.println("Bulk indexing succeeded."); } } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("The list for bulk import is empty!"); } }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Generates the JSON file used to compose the result *///w ww . j av a 2 s .com public static void generateOutputJson() { Map<Integer, String> map = new HashMap<Integer, String>(); for (ClassDesc cd : Configuration.getCurrent().getClasses()) { map.put(cd.getId(), cd.getDdsmPath()); } JSONObject json = new JSONObject(map); ObjectMapper mapper = new ObjectMapper(); try { mapper.writerWithDefaultPrettyPrinter().writeValue( new File(Preferences.getSavingDir() + Configuration.getCurrent().getID() + "OUT.json"), json); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ext.usercenter.UCClient.java
/** * ?queryUserById?json//w w w . j a va 2 s. c om * @param json * @return */ public static User parseJsonForQueryUserById(String json) { ObjectMapper mapper = JackJsonUtil.getMapperInstance(false); User user = new User(); if (StringUtils.isNotEmpty(json)) { JsonNode node = null; try { node = mapper.readTree(json); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } JsonNode jsonNode = node.path("data"); Long privateId = jsonNode.path("privateId").asLong(); String email = jsonNode.path("email").asText(); String realname = jsonNode.path("realname").asText(); String phoneNumber = jsonNode.path("phoneNumber").asText(); user.setId(privateId); user.setUserName(realname); user.setEmail(email); user.setPhoneNumber(phoneNumber); } return user; }
From source file:ext.usercenter.UCClient.java
/** * ?queryUserById?json/*from www .jav a2 s . c o m*/ * @param json * @return */ public static List<UCUserVO> parseJsonForQueryUserListByIds(String json) { ObjectMapper mapper = JackJsonUtil.getMapperInstance(false); List<UCUserVO> ucUserVOList = new ArrayList<UCUserVO>(); if (StringUtils.isNotEmpty(json)) { JsonNode node = null; try { node = mapper.readTree(json); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (node != null && node.path("responsecode").asText().equals("_200")) { JsonNode jsonNode = node.path("data"); Iterator<Entry<String, JsonNode>> fieldIte = jsonNode.fields(); // 2053={"englishName":null,"realname":null} while (fieldIte.hasNext()) { Entry<String, JsonNode> entry = fieldIte.next(); Long userId = new Long(entry.getKey()); JsonNode valueNode = entry.getValue(); String englishName = valueNode.path("englishName").asText(); String realname = valueNode.path("realname").asText(); UCUserVO vo = new UCUserVO(userId, englishName, realname); ucUserVOList.add(vo); } } } return ucUserVOList; }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Builds the JSON representation of the current Configuration and * eventually dumps it on a file.//from ww w . j av a 2s . c o m */ public static void generateInputJson() { Configuration conf = Configuration.getCurrent(); // TODO: REMOVE InstanceDataMultiProvider data = InstanceDataMultiProviderGenerator.build(); data.setId(conf.getID()); setMapJobProfile(data, conf); setMapClassParameters(data, conf); if (conf.getIsPrivate()) { data.setMapPublicCloudParameters(null); setPrivateParameters(data); } else { // Set MapVMConfigurations data.setMapVMConfigurations(null); data.setPrivateCloudParameters(null); if (conf.getHasLtc()) { setEtaR(data, conf); } else { data.setMapPublicCloudParameters(null); } } setMachineLearningProfile(data, conf); if (!Configuration.getCurrent().canSend()) { return; } // Generate Json ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Jdk8Module()); try { mapper.writerWithDefaultPrettyPrinter() .writeValue(new File(Preferences.getSavingDir() + conf.getID() + ".json"), data); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }