List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue
@SuppressWarnings("unchecked") public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
From source file:com.endava.webfundamentals.Main.java
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpRequest = new HttpGet("http://petstore.swagger.wordnik.com/api/api-docs"); HttpResponse httpResponse = httpClient.execute(httpRequest); ObjectMapper objectMapper = new ObjectMapper(); PetStore petStore = objectMapper.readValue(httpResponse.getEntity().getContent(), PetStore.class); PrintWriter out = new PrintWriter("PetStore.html"); out.println("<html>"); out.println("<header>"); out.println(petStore.getInfo().getTitle()); out.println("</header>"); out.println("<body>"); out.println("Api Version " + petStore.getApiVersion()); out.println("Swagger Version " + petStore.getSwaggerVersion()); out.println("<p>"); out.println(petStore.getInfo().getDescription()); out.println("</p>"); out.println("<p>"); out.println(petStore.getInfo().getContact()); out.println("</p>"); out.println(petStore.getInfo().getLicense()); out.println(petStore.getInfo().getLicenseUrl()); out.println("<p>"); out.println(petStore.getInfo().getTermsOfServiceUrl()); out.println("</p>"); out.println("</body>"); out.println("</html>"); out.close();// ww w.j ava2 s . c o m }
From source file:org.test.beans.JsonBeanTest.java
public static void main(String[] arg) throws IOException { System.out.println("Application Started"); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); UserMaster um = mapper.readValue(userMasterJson, UserMaster.class); System.out.println(um);/*from w w w .j a v a2s. com*/ UserTrans ut = mapper.readValue(userTransJson, UserTrans.class); System.out.println(ut); UserTrans utn = mapper.readValue(userTransJsonMore, UserTrans.class); System.out.println(utn); System.out.println(mapper.writeValueAsString(ut)); }
From source file:de.phoenix.submissionpipeline.Core.java
public static void main(String[] args) { ObjectMapper mapper = new ObjectMapper(); SubmissionTask task;/*from www . j a v a 2 s.c om*/ try { task = mapper.readValue(System.in, SubmissionTask.class); } catch (Exception e) { e.printStackTrace(); return; } try { CompileTask compileTask = new CompileTask(task); CharSequenceCompiler<Object> compiler = compileTask.compile(); if (task.getTests().isEmpty()) { writeResult(mapper, new PhoenixSubmissionResult(SubmissionStatus.COMPILED, "Everything fine!")); return; } JUnitTask testTask = new JUnitTask(compiler, task); PhoenixSubmissionResult result = testTask.run(); writeResult(mapper, result); } catch (UserSubmissionException e) { writeResult(mapper, new PhoenixSubmissionResult(SubmissionStatus.ERROR, e.getMessage())); } }
From source file:org.dawnsci.commandserver.mx.example.ActiveMQConsumer.java
public static void main(String[] args) throws Exception { ConnectionFactory connectionFactory = ConnectionFactoryFacade .createConnectionFactory("tcp://sci-serv5.diamond.ac.uk:61616"); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("testQ"); final MessageConsumer consumer = session.createConsumer(queue); connection.start();/* ww w. j a va2 s.c om*/ while (true) { // You have to kill it to stop it! Message m = consumer.receive(1000); if (m != null) { if (m instanceof TextMessage) { TextMessage t = (TextMessage) m; System.out.println(t.getText()); try { ObjectMapper mapper = new ObjectMapper(); final SweepBean colBack = mapper.readValue(t.getText(), SweepBean.class); System.out.println("Data collection found: " + colBack.getDataCollectionId()); } catch (Exception ne) { System.out.println(m + " is not a data collection."); } } else if (m instanceof ObjectMessage) { ObjectMessage o = (ObjectMessage) m; System.out.println(o.getObject()); } } } }
From source file:se.carlengstrom.internetonastick.samples.irc.IrcBot.java
public static void main(final String[] args) throws IOException, IrcException { if (args.length != 1) { System.out.println("Usage: java -jar internet-on-a-stick.jar <configfile>"); System.exit(0);/*from w ww . j a v a 2s . c o m*/ } final ObjectMapper mapper = new ObjectMapper().registerModule(new AutoMatterModule()); final IrcConfig config = mapper.readValue(new File(args[0]), IrcConfig.class); final Configuration configuration = new Configuration.Builder().setName(config.name()) .setRealName(config.realname()).addServer(config.server(), config.port()) .setSocketFactory(new UtilSSLSocketFactory().trustAllCertificates()) .addAutoJoinChannels(config.autoJoinChannels()).addListener(new IrcBot(config)) .buildConfiguration(); //Create our bot with the configuration final PircBotX bot = new PircBotX(configuration); //Connect to the server bot.startBot(); }
From source file:de.oth.keycloak.TestRun.java
public static void main(String[] args) { try {//from w w w . j a v a2 s . c om String server = "http://localhost:8888/auth"; String realm = "master"; String user = "keycloak_admin"; String pwd = "k6ycloakAdmin"; String clientStr = "admin-cli"; String secret = null; String initFileStr = "conf/test_init1.json"; File initFile = new File(initFileStr); if (!initFile.isFile()) { URL url = TestRun.class.getClassLoader().getResource(initFileStr); if (url != null) { initFile = new File(url.getFile()); if (!initFile.isFile()) { log.error("init file does not exist: " + initFile); System.exit(1); } } else { log.error("init file does not exist: " + initFile); System.exit(1); } } Keycloak keycloak = (secret == null) ? Keycloak.getInstance(server, realm, user, pwd, clientStr) : Keycloak.getInstance(server, realm, user, pwd, clientStr, secret); ObjectMapper mapper = new ObjectMapper(); RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class); if (realmsConfig != null) { List<RealmConfig> realmList = realmsConfig.getRealms(); if (realmList == null || realmList.isEmpty()) { log.error("no realms config found 1"); return; } for (RealmConfig realmConf : realmList) { InitKeycloakServer.addRealm(keycloak, realmConf); } } else log.error("no realms config found 2"); } catch (Exception e) { log.error(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:io.rhiot.spec.IoTSpec.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(Option.builder("c").longOpt(CONFIG).desc( "Location of the test configuration file. A default value is 'src/main/resources/test.yaml' for easy IDE testing") .hasArg().build());/* w ww . ja va 2 s. c o m*/ options.addOption(Option.builder("i").longOpt(INSTANCE).desc("Instance of the test; A default value is 1") .hasArg().build()); options.addOption(Option.builder("r").longOpt(REPORT) .desc("Location of the test report. A default value is 'target/report.csv'").hasArg().build()); CommandLine line = parser.parse(options, args); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); TestProfile test = mapper.readValue(new File(line.getOptionValue(CONFIG, "src/main/resources/test.yaml")), TestProfile.class); int instance = Integer.valueOf(line.getOptionValue(INSTANCE, "1")); test.setInstance(instance); String report = line.getOptionValue(REPORT, "target/report.csv"); test.setReport(new CSVReport(report)); LOG.info("Test '" + test.getName() + "' instance " + instance + " started"); final List<Driver> drivers = test.getDrivers(); ExecutorService executorService = Executors.newFixedThreadPool(drivers.size()); List<Future<Void>> results = executorService.invokeAll(drivers, test.getDuration(), TimeUnit.MILLISECONDS); executorService.shutdownNow(); executorService.awaitTermination(5, TimeUnit.SECONDS); results.forEach(result -> { try { result.get(); } catch (ExecutionException execution) { LOG.warn("Exception running driver", execution); } catch (Exception interrupted) { } }); drivers.forEach(driver -> { driver.stop(); try { test.getReport().print(driver); } catch (Exception e) { LOG.warn("Failed to write reports for the driver " + driver); } LOG.debug("Driver " + driver); LOG.debug("\t " + driver.getResult()); }); test.getReport().close(); LOG.info("Test '" + test.getName() + "' instance " + instance + " finished"); }
From source file:org.dawnsci.commandserver.mx.example.TestMarshall.java
public static void main(String[] args) throws Exception { // We want to get the JSON string for this: SweepBean col = new SweepBean("fred", "d0000000001", 0, 100); ProjectBean bean = new ProjectBean(); bean.addSweep(col);/*www. j a va 2 s . c om*/ bean.setStatus(Status.SUBMITTED); bean.setPercentComplete(10); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(bean); System.out.println(jsonString); final ProjectBean beanBack = mapper.readValue(jsonString, ProjectBean.class); System.out.println("Read in equals written out = " + beanBack.equals(bean)); }
From source file:org.anhonesteffort.p25.ACAP25.java
public static void main(String[] args) { try {/*from w ww .j ava2 s . c o m*/ File systemsFile = new File("test.yml"); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); List<System> systems = Arrays.asList(mapper.readValue(systemsFile, System[].class)); new ACAP25(systems).run(); } catch (IOException | SamplesSourceException e) { e.printStackTrace(); } }
From source file:io.rodeo.chute.ChuteMain.java
public static void main(String[] args) throws SQLException, JsonParseException, JsonMappingException, IOException { InputStream is = new FileInputStream(new File(CONFIG_FILENAME)); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); ChuteConfiguration config = mapper.readValue(is, ChuteConfiguration.class); Map<String, Importer> importManagers = new HashMap<String, Importer>(config.importerConfigurations.size()); for (Entry<String, ImporterConfiguration> importerConfig : config.importerConfigurations.entrySet()) { importManagers.put(importerConfig.getKey(), importerConfig.getValue().createImporter()); }/*from w w w . j a v a 2 s. c o m*/ Map<String, Exporter> exportManagers = new HashMap<String, Exporter>(config.exporterConfigurations.size()); for (Entry<String, ExporterConfiguration> exporterConfig : config.exporterConfigurations.entrySet()) { exportManagers.put(exporterConfig.getKey(), exporterConfig.getValue().createExporter()); } for (Entry<String, ConnectionConfiguration> connectionConfig : config.connectionConfigurations.entrySet()) { importManagers.get(connectionConfig.getValue().in) .addProcessor(exportManagers.get(connectionConfig.getValue().out)); } for (Entry<String, Exporter> exportManager : exportManagers.entrySet()) { exportManager.getValue().start(); } for (Entry<String, Importer> importManager : importManagers.entrySet()) { importManager.getValue().start(); } }