List of usage examples for com.fasterxml.jackson.core JsonGenerator writeStartObject
public abstract void writeStartObject() throws IOException, JsonGenerationException;
From source file:org.bndtools.rt.repository.marshall.CapReqJson.java
private static void writeDirective(String key, String value, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("name", key); generator.writeStringField("value", value); generator.writeEndObject();/*w w w. jav a 2s . c om*/ }
From source file:com.netflix.hystrix.contrib.sample.stream.HystrixConfigurationJsonStream.java
public static String convertToString(HystrixConfiguration config) throws IOException { StringWriter jsonString = new StringWriter(); JsonGenerator json = jsonFactory.createGenerator(jsonString); json.writeStartObject(); json.writeStringField("type", "HystrixConfig"); json.writeObjectFieldStart("commands"); for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig() .entrySet()) {/*from w w w. j av a 2s . c o m*/ final HystrixCommandKey key = entry.getKey(); final HystrixCommandConfiguration commandConfig = entry.getValue(); writeCommandConfigJson(json, key, commandConfig); } json.writeEndObject(); json.writeObjectFieldStart("threadpools"); for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> entry : config.getThreadPoolConfig() .entrySet()) { final HystrixThreadPoolKey threadPoolKey = entry.getKey(); final HystrixThreadPoolConfiguration threadPoolConfig = entry.getValue(); writeThreadPoolConfigJson(json, threadPoolKey, threadPoolConfig); } json.writeEndObject(); json.writeObjectFieldStart("collapsers"); for (Map.Entry<HystrixCollapserKey, HystrixCollapserConfiguration> entry : config.getCollapserConfig() .entrySet()) { final HystrixCollapserKey collapserKey = entry.getKey(); final HystrixCollapserConfiguration collapserConfig = entry.getValue(); writeCollapserConfigJson(json, collapserKey, collapserConfig); } json.writeEndObject(); json.writeEndObject(); json.close(); return jsonString.getBuffer().toString(); }
From source file:org.apache.orc.bench.convert.json.JsonWriter.java
static void printStruct(JsonGenerator writer, StructColumnVector batch, TypeDescription schema, int row) throws IOException { writer.writeStartObject(); List<String> fieldNames = schema.getFieldNames(); List<TypeDescription> fieldTypes = schema.getChildren(); for (int i = 0; i < fieldTypes.size(); ++i) { writer.writeFieldName(fieldNames.get(i)); printValue(writer, batch.fields[i], fieldTypes.get(i), row); }//w w w . j ava2 s.c om writer.writeEndObject(); }
From source file:org.bndtools.rt.repository.marshall.CapReqJson.java
private static void writeAttribute(String key, Object value, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("name", key); if (value instanceof Version) { generator.writeStringField("value", value.toString()); generator.writeStringField("type", "Version"); } else if (value instanceof Double || value instanceof Float) { generator.writeStringField("value", value.toString()); generator.writeStringField("type", "Double"); } else if (value instanceof Long || value instanceof Integer) { generator.writeStringField("value", value.toString()); generator.writeStringField("type", "Long"); } else if (value instanceof String) { generator.writeStringField("value", (String) value); } else if (value == null) { throw new IOException("null values not supported"); } else {/*from w w w. ja v a 2s . c om*/ throw new IOException("Unsupported value type " + value.getClass()); } generator.writeEndObject(); }
From source file:org.bndtools.rt.repository.marshall.CapReqJson.java
public static void writeRequirement(Requirement requirement, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("ns", requirement.getNamespace()); Map<String, Object> attrs = requirement.getAttributes(); if (!attrs.isEmpty()) { generator.writeArrayFieldStart("attrs"); for (Entry<String, Object> entry : attrs.entrySet()) { writeAttribute(entry.getKey(), entry.getValue(), generator); }// w w w . j a v a 2 s. c o m generator.writeEndArray(); } Map<String, String> dirs = requirement.getDirectives(); if (!dirs.isEmpty()) { generator.writeArrayFieldStart("dirs"); for (Entry<String, String> entry : dirs.entrySet()) { writeDirective(entry.getKey(), entry.getValue(), generator); } generator.writeEndArray(); } generator.writeEndObject(); }
From source file:org.bndtools.rt.repository.marshall.CapReqJson.java
public static void writeCapability(Capability capability, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("ns", capability.getNamespace()); Map<String, Object> attrs = capability.getAttributes(); if (!attrs.isEmpty()) { generator.writeArrayFieldStart("attrs"); for (Entry<String, Object> entry : attrs.entrySet()) { writeAttribute(entry.getKey(), entry.getValue(), generator); }//from w w w. ja v a 2 s. c o m generator.writeEndArray(); } Map<String, String> dirs = capability.getDirectives(); if (!dirs.isEmpty()) { generator.writeArrayFieldStart("dirs"); for (Entry<String, String> entry : dirs.entrySet()) { writeDirective(entry.getKey(), entry.getValue(), generator); } generator.writeEndArray(); } generator.writeEndObject(); }
From source file:com.meetingninja.csse.database.AgendaDatabaseAdapter.java
public static Agenda createAgenda(Agenda create) throws IOException { Agenda newAgenda = new Agenda(create); // Server URL setup String _url = getBaseUri().build().toString(); // Establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.POST); addRequestHeader(conn, true);/* w w w.j a v a 2 s . c om*/ // prepare POST payload ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object jgen.writeStartObject(); // start agenda jgen.writeStringField(Keys.Agenda.TITLE, create.getTitle()); jgen.writeStringField(Keys.Agenda.MEETING, create.getAttachedMeetingID()); jgen.writeArrayFieldStart(Keys.Agenda.TOPIC); // start topics MAPPER.writeValue(jgen, create.getTopics()); // recursively does // subtopics jgen.writeEndArray(); // end topics jgen.writeEndObject(); // end agenda jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); ps.close(); // Send payload int responseCode = sendPostPayload(conn, payload); String response = getServerResponse(conn); newAgenda = parseAgenda(MAPPER.readTree(response)); return newAgenda; }
From source file:eu.project.ttc.readers.TermSuiteJsonCasSerializer.java
public static void serialize(Writer writer, JCas jCas) throws IOException { JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jg = jsonFactory.createGenerator(writer); jg.useDefaultPrettyPrinter();/*from www .ja va 2 s .c o m*/ jg.writeStartObject(); jg.writeFieldName(F_SDI); writeSDI(jg, jCas); jg.writeFieldName(F_WORD_ANNOTATIONS); writeWordAnnotations(jg, jCas); jg.writeFieldName(F_TERM_OCC_ANNOTATIONS); writeTermOccAnnotations(jg, jCas); jg.writeFieldName(F_FIXED_EXPRESSIONS); writeFixedExpressions(jg, jCas); writeCoveredText(jg, jCas); jg.writeEndObject(); jg.flush(); writer.close(); }
From source file:com.meetingninja.csse.database.ContactDatabaseAdapter.java
public static List<Contact> addContact(String contactUserID) throws IOException { String _url = getBaseUri().build().toString(); URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(IRequest.PUT); addRequestHeader(conn, false);/*from w ww . j a va2 s .c o m*/ SessionManager session = SessionManager.getInstance(); String userID = session.getUserID(); ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, userID); jgen.writeArrayFieldStart(Keys.User.CONTACTS); jgen.writeStartObject(); jgen.writeStringField(Keys.User.CONTACTID, contactUserID); jgen.writeEndObject(); jgen.writeEndArray(); jgen.writeEndObject(); jgen.close(); String payload = json.toString("UTF8"); ps.close(); sendPostPayload(conn, payload); String response = getServerResponse(conn); // TODO: put add useful check here // User userContact=null; // String relationID=null; // String result = new String(); // if (!response.isEmpty()) { // JsonNode contactNode = MAPPER.readTree(response); // if (!contactNode.has(Keys.User.ID)) { // result = "invalid"; // } else { // result = contactNode.get(Keys.User.ID).asText(); // userContact = getUserInfo(result); // relationID = contactNode.get(Keys.User.RELATIONID).asText(); // } // } // if (!result.equalsIgnoreCase("invalid")) // g.setID(result); conn.disconnect(); // Contact contact = new Contact(userContact,relationID); List<Contact> contacts = new ArrayList<Contact>(); contacts = getContacts(userID); return contacts; }
From source file:com.meetingninja.csse.database.NotesDatabaseAdapter.java
private static String getEditPayload(String noteID, String field, String value) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject(); jgen.writeStringField(Keys.Note.ID, noteID); jgen.writeStringField("field", field); jgen.writeStringField("value", value); jgen.writeEndObject();/*from www . ja v a 2 s . co m*/ jgen.close(); String payload = json.toString("UTF8"); ps.close(); Log.d("updatenotepayload", payload); return payload; }