List of usage examples for com.fasterxml.jackson.databind ObjectMapper enable
public ObjectMapper enable(SerializationFeature f)
From source file:com.iflytek.edu.cloud.frame.doc.BuildDocMain.java
public static void main(String[] args) throws Exception { ServiceDocBuilder docBuilder = new ServiceDocBuilder(); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); File jsonFile = getJsonFile(); JsonGenerator jsonGenerator = mapper.getFactory().createGenerator(jsonFile, JsonEncoding.UTF8); jsonGenerator.writeObject(docBuilder.buildDoc()); LOGGER.info("?API?" + jsonFile.getPath()); }
From source file:cz.hobrasoft.pdfmu.jackson.SchemaGenerator.java
public static void main(String[] args) throws JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); // nice formatting SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); Map<String, Type> types = new HashMap<>(); types.put("RpcResponse", RpcResponse.class); types.put("result/inspect", Inspect.class); types.put("result/version set", VersionSet.class); types.put("result/signature add", SignatureAdd.class); types.put("result/empty", EmptyResult.class); for (Map.Entry<String, Type> e : types.entrySet()) { String name = e.getKey(); String filename = String.format("schema/%s.json", name); Type type = e.getValue(); mapper.acceptJsonFormatVisitor(mapper.constructType(type), visitor); JsonSchema jsonSchema = visitor.finalSchema(); mapper.writeValue(new File(filename), jsonSchema); }/*from ww w .ja v a 2 s.c om*/ }
From source file:test.jackson.JacksonNsgiRegister.java
public static void main(String[] args) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String ngsiRcr = new String(Files.readAllBytes(Paths.get(NGSI_FILE))); RegisterContextRequest rcr = objectMapper.readValue(ngsiRcr, RegisterContextRequest.class); System.out.println(objectMapper.writeValueAsString(rcr)); LinkedHashMap association = (LinkedHashMap) rcr.getContextRegistration().get(0).getContextMetadata().get(0) .getValue();//from w w w .j a va 2s . c om Association assocObject = objectMapper.convertValue(association, Association.class); System.out.println(assocObject.getAttributeAssociation().get(0).getSourceAttribute()); rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(1).getContextMetadata().get(0); // System.out.println(rcr.getContextRegistration().get(0).getContextMetadata().get(0).getValue().getClass().getCanonicalName()); // String assocJson = objectMapper.writeValueAsString(association); // Value assocObject = objectMapper.readValue(objectMapper.writeValueAsString(association), Value.class); // System.out.println(association.values().toString()); // System.out.println(assocJson); }
From source file:lab.mage.rate.example.NewsServer.java
public static void main(String[] args) throws Exception { // configure resource final ResourceConfig resourceConfig = new ResourceConfig(); // set news service final NewsService newsService = new NewsService(); resourceConfig.register(newsService); // set Jackson as JSON provider final ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.setDateFormat(new SimpleDateFormat(ISO_8601_DATE_PATTERN)); final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(mapper);/*from ww w.j av a2 s . c o m*/ resourceConfig.register(provider); // create Grizzly instance and add handler final HttpHandler handler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, resourceConfig); final URI uri = new URI("http://localhost:4711/"); final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri); final ServerConfiguration config = server.getServerConfiguration(); config.addHttpHandler(handler, "/api"); // start server.start(); System.in.read(); }
From source file:com.nextdoor.bender.CreateSchema.java
public static void main(String[] args) throws ParseException, InterruptedException, IOException { /*/* w w w . j a v a 2 s. c om*/ * Parse cli arguments */ Options options = new Options(); options.addOption(Option.builder().longOpt("out-file").hasArg() .desc("Filename to output schema to. Default: schema.json").build()); options.addOption(Option.builder().longOpt("docson").hasArg(false) .desc("Create a schema that is able to be read by docson").build()); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); String filename = cmd.getOptionValue("out-file", "schema.json"); /* * Write schema */ BenderSchema schema = new BenderSchema(); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); JsonNode node = schema.getSchema(); if (cmd.hasOption("docson")) { modifyNode(node); } mapper.writeValue(new File(filename), node); }
From source file:de.softwareforge.streamery.StreameryMain.java
public static final void main(String... args) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final DBI h2Dbi = getH2Dbi(); setupData(h2Dbi);//from w w w . j av a 2 s. c o m mapper.enable(SerializationFeature.INDENT_OUTPUT); Query<Data> q = h2Dbi.open().createQuery("SELECT * FROM data").setFetchSize(200).map(DataMapper.INSTANCE); final Observable<Data> observable = JdbiObservable.from(q); observable.subscribe(new JsonStreamer<>(mapper.getFactory())); }
From source file:uk.ac.surrey.ee.iot.fiware.ngsi9.semantic.SemanticConverter.java
public static void main(String[] args) throws JAXBException { SemanticConverter ri = new SemanticConverter(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); RegisterContextRequest rcr = new RegisterContextRequest(); try {/*from www .jav a 2 s . c o m*/ rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class); } catch (Exception e) { } ri.createJenaModel(rcr); // //hMap.put("class", "OnDeviceResource"); //// hMap.put("class", new String[]{"ResourceService"}); // hMap.put("class", new String[]{"VirtualEntity"}); //// hMap.put("hasID", new String[]{"Resource_1"}); // hMap.put("hasID", new String[]{"VirtualEntity_1"}); // hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"}); //// hMap.put("isHostedOn", "PloggBoard_49_BA_01_light"); //// hMap.put("hasType", "Sensor"); //// hMap.put("hasName", "lightsensor49_BA_01"); //// hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService"); //// hMap.put("hasTag", "light sensor 49,1st,BA,office"); // hMap.put("hasLatitude", new String[]{"51.243455"}); //// hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/"); //// hMap.put("hasResourceID", "Resource_53_BA_power_sensor"); //// hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49"); // hMap.put("hasAltitude", new String[]{""}); // hMap.put("hasLongitude", new String[]{"-0.588088"}); //// hMap.put("hasTimeOffset", "20"); // // //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#"; // //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#"; // //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl"; // ri.createJenaModel(hMap); }
From source file:org.jaqpot.core.elastic.ElasticSearchWriter.java
License:asdf
public static void main(String... args) throws IOException { User u = UserBuilder.builder("jack.sparrow").setHashedPassword(UUID.randomUUID().toString()) .setMail("jack.sparrow@gmail.com").setMaxBibTeX(17680).setMaxFeatures(12678).setMaxModels(9999) .setName("Jack Sparrow").setMaxSubstances(1000).setMaxWeeklyPublishedFeatures(345) .setMaxWeeklyPublishedModels(67).setMaxWeeklyPublishedSubstances(5).setMaxParallelTasks(10).build(); //u.setId(null); BibTeX b = BibTeXBuilder.builder("WhaTevEr14").setAbstract("asdf").setAddress("sdfsdfsd") .setAnnotation("slkfsdlf").setAuthor("a").setBibType(BibTeX.BibTYPE.Article).setBookTitle("t6hdth") .setChapter("uthjsdfbkjs").setCopyright("sdfsdf").setCrossref("other").setEdition("234234") .setEditor("me").setISBN("23434234").setISSN("10010231230").setJournal("haha").setKey("lalala") .setKeywords("This is a set of keywords").setNumber("1").setPages("101-123") .setSeries("Some series").setTitle("Lololo").setURL("http://some.url.ch/").setVolume("100") .setYear("2010").build(); ROG rog = new ROG(false); Model m = rog.nextModel();//from w w w .jav a 2s . c o m m = new ModelMetaStripper(m).strip(); Feature f = new Feature(); f.setId("456"); Set<String> ontClasses = new HashSet<>(); ontClasses.add("ot:Feature"); ontClasses.add("ot:NumericFeature"); f.setOntologicalClasses(ontClasses); f.setMeta(MetaInfoBuilder.builder().addComments("this is a comment", "and a second one") .addTitles("My first feature", "a nice feature").addSubjects("feature of the day").build()); f.setUnits("mJ"); ElasticSearchWriter writer = new ElasticSearchWriter(b); InetSocketTransportAddress addrOpenTox = new InetSocketTransportAddress("147.102.82.32", 49101); InetSocketTransportAddress addrLocal = new InetSocketTransportAddress("localhost", 9300); writer.client = new TransportClient() //.addTransportAddress(addrLocal) .addTransportAddress(addrOpenTox); ObjectMapper om = new ObjectMapper(); om.enable(SerializationFeature.INDENT_OUTPUT); writer.om = om; System.out.println("http://147.102.82.32:49234/jaqpot/" + XmlNameExtractor.extractName(writer.entity.getClass()) + "/" + writer.index()); }
From source file:org.n52.iceland.statistics.api.utils.KibanaExporter.java
public static void main(String args[]) throws Exception { if (args.length != 2) { System.out.printf("Usage: java KibanaExporter.jar %s %s\n", "localhost:9300", "my-cluster-name"); System.exit(0);/*from w ww . j ava2s.c o m*/ } if (!args[0].contains(":")) { throw new IllegalArgumentException( String.format("%s not a valid format. Expected <hostname>:<port>.", args[0])); } // set ES address String split[] = args[0].split(":"); InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getByName(split[0]), Integer.parseInt(split[1], 10)); // set cluster name Builder tcSettings = Settings.settingsBuilder(); tcSettings.put("cluster.name", args[1]); System.out.println("Connection to " + args[1]); client = TransportClient.builder().settings(tcSettings).build(); client.addTransportAddress(address); // search index pattern for needle searchIndexPattern(); KibanaConfigHolderDto holder = new KibanaConfigHolderDto(); System.out.println("Reading .kibana index"); SearchResponse resp = client.prepareSearch(".kibana").setSize(1000).get(); Arrays.asList(resp.getHits().getHits()).stream().map(KibanaExporter::parseSearchHit).forEach(holder::add); System.out.println("Reading finished"); ObjectMapper mapper = new ObjectMapper(); // we love pretty things mapper.enable(SerializationFeature.INDENT_OUTPUT); File f = new File("kibana_config.json"); try (FileOutputStream out = new FileOutputStream(f, false)) { mapper.writeValue(out, holder); } System.out.println("File outputted to: " + f.getAbsolutePath()); client.close(); }
From source file:test.SemanticConverter.java
public static void main(String[] args) throws JAXBException { SemanticConverter ri = new SemanticConverter(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); RegisterContextRequest rcr = new RegisterContextRequest(); try {//from ww w . j ava2s.c o m rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class); } catch (Exception e) { } // RegisterContextRequest rcr = rm.unmarshallRequest(ri.NGSI_FILE); rcr.setTimestamp(Instant.now()); ri.createJenaModel(rcr); // //hMap.put("class", "OnDeviceResource"); //// hMap.put("class", new String[]{"ResourceService"}); // hMap.put("class", new String[]{"VirtualEntity"}); //// hMap.put("hasID", new String[]{"Resource_1"}); // hMap.put("hasID", new String[]{"VirtualEntity_1"}); // hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"}); //// hMap.put("isHostedOn", "PloggBoard_49_BA_01_light"); //// hMap.put("hasType", "Sensor"); //// hMap.put("hasName", "lightsensor49_BA_01"); //// hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService"); //// hMap.put("hasTag", "light sensor 49,1st,BA,office"); // hMap.put("hasLatitude", new String[]{"51.243455"}); //// hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/"); //// hMap.put("hasResourceID", "Resource_53_BA_power_sensor"); //// hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49"); // hMap.put("hasAltitude", new String[]{""}); // hMap.put("hasLongitude", new String[]{"-0.588088"}); //// hMap.put("hasTimeOffset", "20"); // // //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#"; // //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#"; // //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl"; // ri.createJenaModel(hMap); }