List of usage examples for com.fasterxml.jackson.core JsonFactory JsonFactory
public JsonFactory()
From source file:pl.edu.pwr.iiar.zak.thermalKit.util.DBConnector.java
public DBConnector() throws IOException { JsonFactory f = new JsonFactory(); JsonParser jp = f.createParser(new File("~/.jgenerilorc")); JsonNode node = jp.getCodec().readTree(jp); databaseName = node.get("database").asText(); }
From source file:com.virtlink.commons.configuration2.jackson.JsonConfiguration.java
/** * Initializes a new instance of the {@link JsonConfiguration} class. * * @param config The configuration whose nodes to copy into this configuration. *//* w ww .j a v a 2 s. co m*/ public JsonConfiguration(final HierarchicalConfiguration<ImmutableNode> config) { super(new JsonFactory(), config); }
From source file:chiliad.parser.pdf.output.JSONOutput.java
public JSONOutput(Writer writer) { JsonFactory jfactory = new JsonFactory(); try {/*from ww w . ja v a 2s . co m*/ gen = jfactory.createGenerator(writer); } catch (IOException ex) { throw new ParserOutputException("Failed to writer JSON output.", ex); } }
From source file:com.pursuer.reader.easyrss.data.parser.TagJSONParser.java
public void parse() throws JsonParseException, IOException, IllegalStateException { final JsonFactory factory = new JsonFactory(); final JsonParser parser = factory.createJsonParser(input); Tag tag = new Tag(); int level = 0; boolean found = false; while (parser.nextToken() != null) { final String name = parser.getCurrentName(); switch (parser.getCurrentToken()) { case START_OBJECT: case START_ARRAY: level++;/* w w w . ja va 2 s .c o m*/ break; case END_OBJECT: case END_ARRAY: level--; break; case VALUE_STRING: if (level == 3) { if ("id".equals(name)) { tag.setUid(parser.getText()); } else if ("sortid".equals(name)) { tag.setSortId(parser.getText()); } } case FIELD_NAME: if (level == 1 && "tags".equals(name)) { found = true; } default: } if (level == 2) { if (tag.getUid() != null && listener != null) { listener.onTagRetrieved(tag); } tag = new Tag(); } } parser.close(); if (!found) { throw new IllegalStateException("Invalid JSON input"); } }
From source file:com.tellapart.taba.Transport.java
/** * Encode a bundle of Events for multiple Client IDs. * * @param clientToNameToEvents Map from Client ID -> Tab Name -> List of Event objects. * * @return A string denoting the event to be uploaded to the Taba Agent. *///w ww. ja va2s . c om public static String encodeMultiClient(Map<String, Map<String, List<Event>>> clientToNameToEvents) { List<String> parts = new ArrayList<>(); // TODO(mike): Use Multimap for default list. // TODO(mike): join java and python PROTOCOL_VERSION_CURRENT together ('1'); JsonFactory factory = new JsonFactory(); parts.add("1"); parts.add(""); for (Map.Entry<String, Map<String, List<Event>>> entry : clientToNameToEvents.entrySet()) { String client = entry.getKey(); Map<String, List<Event>> nameToEvents = entry.getValue(); parts.add(client); parts.add(""); for (Map.Entry<String, List<Event>> entry2 : nameToEvents.entrySet()) { String name = entry2.getKey(); List<Event> events = entry2.getValue(); parts.add(name); for (Event event : events) { try { parts.add(encodeEvent(event, factory)); } catch (IOException e) { e.printStackTrace(); } } parts.add(""); } parts.add(""); } parts.add(""); return partJoiner.join(parts); }
From source file:io.airlift.event.client.JsonEventWriter.java
@Inject public JsonEventWriter(Set<EventTypeMetadata<?>> eventTypes) { Preconditions.checkNotNull(eventTypes, "eventTypes is null"); this.jsonFactory = new JsonFactory(); ImmutableMap.Builder<Class<?>, JsonSerializer<?>> serializerBuilder = ImmutableMap.builder(); for (EventTypeMetadata<?> eventType : eventTypes) { serializerBuilder.put(eventType.getEventClass(), new EventJsonSerializer<>(eventType)); }//from w ww . ja va 2 s. co m this.serializers = serializerBuilder.build(); }
From source file:org.springframework.cloud.stream.metrics.config.MetricJsonSerializerTests.java
@Test public void validateAlwaysGMTDateAndFormat() throws Exception { Date date = new Date(1493060197188L); // Mon Apr 24 14:56:37 EDT 2017 Metric<Number> metric = new Metric<Number>("Hello", 123, date); JsonFactory factory = new JsonFactory(); StringWriter writer = new StringWriter(); JsonGenerator jsonGenerator = factory.createGenerator(writer); Serializer ser = new Serializer(); ser.serialize(metric, jsonGenerator, null); jsonGenerator.flush();/* w ww .j a v a 2 s . c o m*/ JSONObject json = new JSONObject(writer.toString()); String serializedTimestamp = json.getString("timestamp"); assertEquals("2017-04-24T18:56:37.188Z", serializedTimestamp); }
From source file:com.enremmeta.onenow.Utils.java
public static Config loadConfig(String fileName, Class<? extends Config> configClass) throws MalformedURLException, IOException { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.ALLOW_COMMENTS, true); ObjectMapper mapper = new ObjectMapper(jsonFactory); Config config;/* w w w.ja va 2 s .c o m*/ if (fileName.startsWith("http://") || fileName.startsWith("https://")) { URL url = new URL(fileName); config = mapper.readValue(url, configClass); } else { File file = new File(fileName); config = mapper.readValue(file, configClass); } return config; }
From source file:com.sangupta.comparator.JSONComparer.java
/** * Compare two JSON string representations. * /* w w w . j av a2 s . c o m*/ * @param json1 * the first representation * * @param json2 * 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(String json1, String json2) throws JsonProcessingException, IOException { if (json1 == null || json2 == null) { return false; } if (json1 == json2) { return true; } JsonFactory factory = new JsonFactory(); factory.enable(Feature.ALLOW_COMMENTS); ObjectMapper mapper = new ObjectMapper(); JsonNode node1 = mapper.readTree(json1); JsonNode node2 = mapper.readTree(json2); return node1.equals(node2); }
From source file:be.dnsbelgium.rdap.jackson.AbstractSerializerTest.java
@SuppressWarnings("unchecked") public void serializeAndAssertEquals(String expected, S o, SerializerProvider sp) throws IOException { JsonFactory factory = new JsonFactory(); T serializer = getSerializer();//from ww w .j a v a 2s . c o m StringWriter sw = new StringWriter(); JsonGenerator jgen = factory.createJsonGenerator(sw); serializer.serialize(o, jgen, sp); // unchecked jgen.flush(); sw.flush(); String result = sw.toString(); sw.close(); assertEquals(expected, result); }