List of usage examples for com.fasterxml.jackson.core JsonFactory JsonFactory
public JsonFactory()
From source file:net.javacrumbs.json2xml.JsonXmlReader.java
public void parse(InputSource input) throws IOException, SAXException { JsonParser jsonParser = new JsonFactory().createParser(input.getCharacterStream()); new JsonSaxAdapter(jsonParser, contentHandler, namespaceUri, addTypeAttributes, artificialRootName, elementNameConverter).parse(); }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.SteeringTest.java
License:asdf
public void setupCrConfig() throws IOException { String resourcePath = "publish/CrConfig.json"; InputStream inputStream = getClass().getClassLoader().getResourceAsStream(resourcePath); if (inputStream == null) { fail("Could not find file '" + resourcePath + "' needed for test from the current classpath as a resource!"); }//ww w . j av a 2 s . c om JsonNode jsonNode = new ObjectMapper(new JsonFactory()).readTree(inputStream); Iterator<String> deliveryServices = jsonNode.get("deliveryServices").fieldNames(); while (deliveryServices.hasNext()) { String dsId = deliveryServices.next(); if (targetDomains.containsKey(dsId)) { targetDomains.put(dsId, jsonNode.get("deliveryServices").get(dsId).get("domains").get(0).asText()); } } assertThat(steeringDeliveryServiceId, not(nullValue())); assertThat(targetDomains.isEmpty(), equalTo(false)); for (String deliveryServiceId : targetDomains.keySet()) { Iterator<String> cacheIds = jsonNode.get("contentServers").fieldNames(); while (cacheIds.hasNext()) { String cacheId = cacheIds.next(); JsonNode cacheNode = jsonNode.get("contentServers").get(cacheId); if (!cacheNode.has("deliveryServices")) { continue; } if (cacheNode.get("deliveryServices").has(deliveryServiceId)) { int port = cacheNode.get("port").asInt(); String portText = (port == 80) ? "" : ":" + port; validLocations.add("http://" + cacheId + "." + targetDomains.get(deliveryServiceId) + portText + "/stuff?fakeClientIpAddress=12.34.56.78"); } } } assertThat(validLocations.isEmpty(), equalTo(false)); }
From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapter.java
public int processRecord(String singleRecord) throws IOException { JsonFactory factory = new JsonFactory(); JsonParser parser = factory.createParser(new StringReader(singleRecord)); return processRecord(parser); }
From source file:org.apache.olingo.client.core.serialization.JsonSerializer.java
@SuppressWarnings("unchecked") @Override//w ww . j a va 2s . c om public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException { final T obj = container == null ? null : container.getPayload(); try { final JsonGenerator json = new JsonFactory().createGenerator(writer); if (obj instanceof EntityCollection) { new JsonEntitySetSerializer(serverMode, contentType) .doContainerSerialize((ResWrap<EntityCollection>) container, json); } else if (obj instanceof Entity) { new JsonEntitySerializer(serverMode, contentType).doContainerSerialize((ResWrap<Entity>) container, json); } else if (obj instanceof Property) { new JsonPropertySerializer(serverMode, contentType) .doContainerSerialize((ResWrap<Property>) container, json); } else if (obj instanceof Link) { link((Link) obj, json); } else if (obj instanceof URI) { reference((ResWrap<URI>) container, json); } json.flush(); } catch (final IOException e) { throw new ODataSerializerException(e); } catch (final EdmPrimitiveTypeException e) { throw new ODataSerializerException(e); } }
From source file:com.sangupta.comparator.JSONComparer.java
/** * Compare two JSON representations./*from w w w . j ava 2 s. c o m*/ * * @param reader1 * the first representation * * @param reader2 * the second representation * * @return <code>true</code> if the two JSON representations represent the * same object, <code>false</code> otherwise. * * @throws JsonParseException * if something fails * * @throws JsonProcessingException * if something fails * * @throws IOException * if something fails * */ public static boolean compareJson(Reader reader1, Reader reader2) throws JsonProcessingException, IOException { if (reader1 == null || reader2 == null) { return false; } if (reader1 == reader2) { return true; } JsonFactory factory = new JsonFactory(); factory.enable(Feature.ALLOW_COMMENTS); ObjectMapper mapper = new ObjectMapper(); JsonNode node1 = mapper.readTree(reader1); JsonNode node2 = mapper.readTree(reader2); return node1.equals(node2); }
From source file:com.apteligent.ApteligentJavaClient.java
/** * Query the API for a list of Apps, and the details of each App * @return map of App IDs -> App Objects *///from w ww.j a v a 2s . c om public Map<String, App> getAppListing() { Map<String, App> map = null; try { String urlParameters = "?attributes=appName%2CappType%2CappVersions%2CcrashPercent%2Cdau%2Clatency%2C" + "latestAppStoreReleaseDate%2ClatestVersionString%2ClinkToAppStore%2CiconURL%2Cmau%2Crating%2Crole"; HttpsURLConnection conn = sendGetRequest(API_APPS, urlParameters); JsonFactory jsonFactory = new JsonFactory(); JsonParser jp = jsonFactory.createParser(conn.getInputStream()); ObjectMapper mapper = getObjectMapper(); map = mapper.readValue(jp, new TypeReference<Map<String, App>>() { }); } catch (IOException ioex) { ioex.printStackTrace(); } return map; }
From source file:org.helm.notation2.wsadapter.MonomerWSLoader.java
/** * Loads the monomer store using the URL configured in * {@code MonomerStoreConfiguration} and the polymerType that was given to * constructor./*from w w w. j av a 2s. com*/ * * @param attachmentDB the attachments stored in Toolkit. * * @return Map containing monomers * * @throws IOException * @throws URISyntaxException * @throws EncoderException */ public Map<String, Monomer> loadMonomerStore(Map<String, Attachment> attachmentDB) throws IOException, URISyntaxException, EncoderException { Map<String, Monomer> monomers = new HashMap<String, Monomer>(); CloseableHttpClient httpclient = HttpClients.createDefault(); // There is no need to provide user credentials // HttpClient will attempt to access current user security context // through Windows platform specific methods via JNI. CloseableHttpResponse response = null; try { HttpGet httpget = new HttpGet(new URIBuilder( MonomerStoreConfiguration.getInstance().getWebserviceMonomersFullURL() + polymerType).build()); LOG.debug("Executing request " + httpget.getRequestLine()); response = httpclient.execute(httpget); LOG.debug(response.getStatusLine().toString()); JsonFactory jsonf = new JsonFactory(); InputStream instream = response.getEntity().getContent(); if (response.getStatusLine().getStatusCode() != 200) { throw new MonomerLoadingException("Response from the Webservice throws an error"); } JsonParser jsonParser = jsonf.createJsonParser(instream); monomers = deserializeMonomerStore(jsonParser, attachmentDB); LOG.debug(monomers.size() + " " + polymerType + " monomers loaded"); EntityUtils.consume(response.getEntity()); } finally { if (response != null) { response.close(); } if (httpclient != null) { httpclient.close(); } } return monomers; }
From source file:io.seldon.spark.actions.JobUtils.java
public static String mapToJson(Map<String, String> m) { JsonFactory jsonFactory = new JsonFactory(); StringWriter sw = new StringWriter(); try {//from ww w.j a v a 2 s . c o m JsonGenerator jg = jsonFactory.createGenerator(sw); jg.writeStartObject(); for (Map.Entry<String, String> entry : m.entrySet()) { jg.writeStringField(entry.getKey(), entry.getValue()); } jg.writeEndObject(); jg.close(); } catch (IOException e) { e.printStackTrace(); } return sw.toString(); }
From source file:net.solarnetwork.web.support.JSONView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { PropertyEditorRegistrar registrar = this.propertyEditorRegistrar; Enumeration<String> attrEnum = request.getAttributeNames(); while (attrEnum.hasMoreElements()) { String key = attrEnum.nextElement(); Object val = request.getAttribute(key); if (val instanceof PropertyEditorRegistrar) { registrar = (PropertyEditorRegistrar) val; break; }/*from w w w . j ava 2 s.c om*/ } response.setCharacterEncoding(UTF8_CHAR_ENCODING); response.setContentType(getContentType()); Writer writer = response.getWriter(); if (this.includeParentheses) { writer.write('('); } JsonGenerator json = new JsonFactory().createGenerator(writer); json.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); if (indentAmount > 0) { json.useDefaultPrettyPrinter(); } json.writeStartObject(); for (String key : model.keySet()) { Object val = model.get(key); writeJsonValue(json, key, val, registrar); } json.writeEndObject(); json.close(); if (this.includeParentheses) { writer.write(')'); } }