List of usage examples for com.fasterxml.jackson.core JsonFactory JsonFactory
public JsonFactory()
From source file:KV78Tester.java
public void checkLines(BufferedReader in) throws JsonParseException, IOException { JsonFactory f = new JsonFactory(); JsonParser jp = f.createJsonParser(in); String line = ""; jp.nextToken();//w ww . j av a 2 s. c o m while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); if (namefield != null && namefield.contains("_")) { line = namefield; } jp.nextToken(); if ("Actuals".equals(namefield)) { while (jp.nextToken() != JsonToken.END_OBJECT) { jp.getCurrentName(); jp.nextToken(); while (jp.nextToken() != JsonToken.END_OBJECT) { jp.nextToken(); } } } else if ("Network".equals(namefield)) { while (jp.nextToken() != JsonToken.END_OBJECT) { int userstop = Integer.parseInt(jp.getCurrentName()); jp.nextToken(); checkStop(jp, line, userstop); } } } }
From source file:com.github.heuermh.ensemblrestclient.JacksonVariationConverterTest.java
@Before public void setUp() { jsonFactory = new JsonFactory(); converter = new JacksonVariationConverter(jsonFactory); }
From source file:com.cinnober.msgcodec.json.TypeScannerJsonParserTest.java
@Test public void test2() throws IOException { JsonParser p = new JsonFactory().createParser("{\"a\":1, \"b\":1.1, \"$type\":\"x\"}"); p.nextToken(); // START_OBJECT p.nextToken(); // FIELD_NAME TypeScannerJsonParser p2 = new TypeScannerJsonParser(p); assertEquals("x", p2.findType()); assertNextField("a", p2); assertNextIntValue(1, p2);//from www . j a v a2 s .co m assertNextField("b", p2); assertNextFloatValue(1.1, p2); assertEquals(JsonToken.END_OBJECT, p2.nextToken()); assertNull(p2.nextToken()); }
From source file:ai.susi.geo.GeoJsonReader.java
public GeoJsonReader(final InputStream is, final int concurrency) throws JsonParseException, IOException { this.concurrency = concurrency; this.featureQueue = new ArrayBlockingQueue<Feature>(Runtime.getRuntime().availableProcessors() * 2 + 1); JsonFactory factory = new JsonFactory(); this.parser = factory.createParser(is); }
From source file:com.github.heuermh.ensemblrestclient.EnsemblRestClientFactory.java
/** * Create a new Ensembl REST client factory with the specified default endpoint URL. * * @since 1.3/*from w w w . j av a 2s . com*/ * @param defaultEndpointUrl default endpoint URL, must not be null */ public EnsemblRestClientFactory(final String defaultEndpointUrl) { this(defaultEndpointUrl, new JsonFactory()); }
From source file:com.ericsson.eiffel.remrem.publish.service.EventTemplateHandler.java
public JsonNode eventTemplateParser(String jsonData, String eventName) { JsonNode updatedJson = null;/*from w w w . j a va 2s. c o m*/ JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); JsonNode rootNode = null; try { String eventTemplate = accessFileInSemanticJar(EVENT_TEMPLATE_PATH + eventName.toLowerCase() + ".json"); rootNode = mapper.readTree(jsonData); updatedJson = mapper.readValue(eventTemplate, JsonNode.class); } catch (IOException e) { log.error(e.getMessage(), e); } // For each key/value pair for parsing to template Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields(); while (fieldsIterator.hasNext()) { Map.Entry<String, JsonNode> field = fieldsIterator.next(); // Parse values to template // Check if POJO required for update in event template Pattern p = Pattern.compile(REGEXP_END_DIGITS); // if ends with [d+] Matcher m = p.matcher(field.getKey()); String myKey = "$." + templateParamHandler(field.getKey()); if (field.getValue().toString().equals("\"<%DELETE%>\"")) { updatedJson = jsonPathHandlerDelete(updatedJson, myKey); } else if (m.find()) { String myValue = field.getValue().toString(); try { // Fetch Class name in Event Schema String eventSchema = accessFileInSemanticJar(EVENT_SCHEMA_PATH + eventName + ".json"); // Filter javatype from Event Schema = class name JsonNode jsonFromSchema = JsonPath.using(configuration).parse(eventSchema.toString()) .read(schemaClassPathHandler(field.getKey().replaceAll(REGEXP_END_DIGITS, ""))); String myClassName = jsonFromSchema.toString().replace("[", "").replace("]", "").replace("\"", ""); // Ex ["com.ericsson.eiffel.semantics.events.PersistentLog"] to com.ericsson.eiffel.semantics.events.PersistentLog // Initiate Class via reflection and map values - POJO Class myClass = Class.forName(myClassName); Object mapped2Pojo = mapper.readValue(myValue, myClass); updatedJson = jsonPathHandlerSet(updatedJson, myKey, mapped2Pojo); } catch (ClassNotFoundException e) { // No POJO required for adding new item in Array (ie no key/value pairs) updatedJson = jsonPathHandlerSet(updatedJson, myKey, myValue.toString().replace("\"", "")); } catch (Exception e) { log.error(e.getMessage(), e); } } else { // No POJO needed for update Object myValue = field.getValue(); updatedJson = jsonPathHandlerSet(updatedJson, myKey, myValue); } } // while return updatedJson; }
From source file:org.jsfr.json.JacksonParserTest.java
@Test public void testLargeJsonJackson() throws Exception { final AtomicLong counter = new AtomicLong(); ObjectMapper om = new ObjectMapper(); JsonFactory f = new JsonFactory(); JsonParser jp = f.createParser(read("allthethings.json")); long start = System.currentTimeMillis(); jp.nextToken();/* ww w.jav a2 s. c o m*/ jp.nextToken(); jp.nextToken(); while (jp.nextToken() == JsonToken.FIELD_NAME) { if (jp.nextToken() == JsonToken.START_OBJECT) { TreeNode tree = om.readTree(jp); counter.incrementAndGet(); LOGGER.trace("value: {}", tree); } } jp.close(); LOGGER.info("Jackson processes {} value in {} millisecond", counter.get(), System.currentTimeMillis() - start); }
From source file:org.elasticsearch.client.sniff.ElasticsearchNodesSnifferParseTests.java
private void checkFile(String file, Node... expected) throws IOException { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); if (in == null) { throw new IllegalArgumentException("Couldn't find [" + file + "]"); }/*from w w w . ja va2 s . com*/ try { HttpEntity entity = new InputStreamEntity(in, ContentType.APPLICATION_JSON); List<Node> nodes = ElasticsearchNodesSniffer.readHosts(entity, Scheme.HTTP, new JsonFactory()); /* * Use these assertions because the error messages are nicer * than hasItems and we know the results are in order because * that is how we generated the file. */ assertThat(nodes, hasSize(expected.length)); for (int i = 0; i < expected.length; i++) { assertEquals(expected[i], nodes.get(i)); } } finally { in.close(); } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.LocationsTest.java
@Test public void itGetsAListOfLocations() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:3333/crs/locations"); CloseableHttpResponse response = null; try {// www .ja va2 s.c o m response = closeableHttpClient.execute(httpGet); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); ObjectMapper objectMapper = new ObjectMapper(new JsonFactory()); JsonNode jsonNode = objectMapper.readTree(EntityUtils.toString(response.getEntity())); assertThat(jsonNode.get("locations").get(0).asText(), not(equalTo(""))); } finally { if (response != null) response.close(); } }
From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapterPrimaryKeyFinder.java
public Object[] findKey(String json) throws IOException { JsonFactory factory = new JsonFactory(); JsonParser parser = factory.createParser(new StringReader(json)); return Arrays.copyOf(findKey(parser), keyElementArray.length); }