List of usage examples for com.fasterxml.jackson.core JsonGenerator writeEndObject
public abstract void writeEndObject() throws IOException, JsonGenerationException;
From source file:com.netflix.hystrix.serial.SerialHystrixConfiguration.java
private static void serializeConfiguration(HystrixConfiguration config, JsonGenerator json) { try {// ww w . j av a2s . co m json.writeStartObject(); json.writeStringField("type", "HystrixConfig"); json.writeObjectFieldStart("commands"); for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig() .entrySet()) { 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(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.orc.bench.convert.json.JsonWriter.java
static void printRow(JsonGenerator writer, VectorizedRowBatch batch, TypeDescription schema, int row) throws IOException { if (schema.getCategory() == TypeDescription.Category.STRUCT) { List<TypeDescription> fieldTypes = schema.getChildren(); List<String> fieldNames = schema.getFieldNames(); writer.writeStartObject();/*from w w w . ja va2 s .co m*/ for (int c = 0; c < batch.cols.length; ++c) { writer.writeFieldName(fieldNames.get(c)); printValue(writer, batch.cols[c], fieldTypes.get(c), row); } writer.writeEndObject(); } else { printValue(writer, batch.cols[0], schema, row); } }
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();// w w w . j a v a2s .c o m json.writeStringField("type", "HystrixConfig"); json.writeObjectFieldStart("commands"); for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig() .entrySet()) { 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:com.meetingninja.csse.database.ProjectDatabaseAdapter.java
public static Project createProject(Project p) throws IOException, MalformedURLException { // Server URL setup String _url = getBaseUri().build().toString(); // establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); addRequestHeader(conn, true);//from www .j a v a 2 s. co m // 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(); jgen.writeStringField(Keys.Project.TITLE, p.getProjectTitle()); jgen.writeArrayFieldStart(Keys.Project.MEETINGS); for (Meeting meeting : p.getMeetings()) { jgen.writeStartObject(); jgen.writeStringField(Keys.Meeting.ID, meeting.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeArrayFieldStart(Keys.Project.NOTES); for (Note note : p.getNotes()) { jgen.writeStartObject(); jgen.writeStringField(Keys.Note.ID, note.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeArrayFieldStart(Keys.Project.MEMBERS); for (User member : p.getMembers()) { jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, member.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeEndObject(); jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); ps.close(); // send payload sendPostPayload(conn, payload); String response = getServerResponse(conn); // prepare to get the id of the created Meeting // Map<String, String> responseMap = new HashMap<String, String>(); /* * result should get valid={"meetingID":"##"} */ String result = new String(); if (!response.isEmpty()) { // responseMap = MAPPER.readValue(response, // new TypeReference<HashMap<String, String>>() { // }); JsonNode projectNode = MAPPER.readTree(response); if (!projectNode.has(Keys.Project.ID)) { result = "invalid"; } else result = projectNode.get(Keys.Project.ID).asText(); } if (!result.equalsIgnoreCase("invalid")) p.setProjectID(result); conn.disconnect(); return p; }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.organisational.CompanyJSON.java
public final static void company2JSON(Company company, JsonGenerator jgenerator) throws IOException { jgenerator.writeStartObject();/*ww w . j a v a2 s.co m*/ jgenerator.writeNumberField(CMP_ID, company.getId()); jgenerator.writeNumberField(CMP_VERSION, company.getVersion()); jgenerator.writeStringField(CMP_NAME, company.getName()); jgenerator.writeStringField(CMP_DESCRIPTION, company.getDescription()); jgenerator.writeArrayFieldStart(CMP_APP_ID); for (Application app : company.getApplications()) jgenerator.writeNumber(app.getId()); jgenerator.writeEndArray(); jgenerator.writeArrayFieldStart(CMP_OST_ID); for (OSType ost : company.getOsTypes()) jgenerator.writeNumber(ost.getId()); jgenerator.writeEndArray(); jgenerator.writeEndObject(); }
From source file:org.apache.orc.bench.convert.json.JsonWriter.java
private static void printMap(JsonGenerator writer, MapColumnVector vector, TypeDescription schema, int row) throws IOException { writer.writeStartArray();//from w w w .ja v a 2 s. c o m TypeDescription keyType = schema.getChildren().get(0); TypeDescription valueType = schema.getChildren().get(1); int offset = (int) vector.offsets[row]; for (int i = 0; i < vector.lengths[row]; ++i) { writer.writeStartObject(); writer.writeFieldName("_key"); printValue(writer, vector.keys, keyType, offset + i); writer.writeFieldName("_value"); printValue(writer, vector.values, valueType, offset + i); writer.writeEndObject(); } writer.writeEndArray(); }
From source file:eu.project.ttc.readers.TermSuiteJsonCasSerializer.java
private static void writeTermOccAnnotations(JsonGenerator jg, JCas jCas) throws IOException { jg.writeStartArray();/*w ww . j a v a 2 s.c o m*/ FSIterator<Annotation> it = jCas.getAnnotationIndex(TermOccAnnotation.type).iterator(); while (it.hasNext()) { TermOccAnnotation toa = (TermOccAnnotation) it.next(); jg.writeStartObject(); writeStringFSArrayField(jg, F_PATTERN, toa.getPattern()); writeStringField(jg, F_SPOTTING_RULE_NAME, toa.getSpottingRuleName()); writeStringField(jg, F_TERM_KEY, toa.getTermKey()); writeIntFSArrayField(jg, F_WORDS, toa.getWords()); writeOffsets(jg, toa); jg.writeEndObject(); } jg.writeEndArray(); }
From source file:io.protostuff.JsonIOUtil.java
/** * Serializes the {@code message} into a JsonGenerator using the given {@code schema}. *///from w ww . j av a 2 s . c om public static <T> void writeTo(JsonGenerator generator, T message, Schema<T> schema, boolean numeric) throws IOException { generator.writeStartObject(); final JsonOutput output = new JsonOutput(generator, numeric, schema); schema.writeTo(output, message); if (output.isLastRepeated()) generator.writeEndArray(); generator.writeEndObject(); }
From source file:io.seldon.spark.actions.JobUtils.java
public static String getJsonFromActionData(ActionData actionData) { JsonFactory jsonFactory = new JsonFactory(); StringWriter sw = new StringWriter(); try {//from ww w . j a v a 2 s . com JsonGenerator jg = jsonFactory.createGenerator(sw); jg.writeStartObject(); jg.writeStringField("timestamp_utc", actionData.timestamp_utc); jg.writeStringField("client", actionData.client); jg.writeStringField("client_userid", actionData.client_userid); jg.writeNumberField("userid", actionData.userid); jg.writeNumberField("itemid", actionData.itemid); jg.writeStringField("client_itemid", actionData.client_itemid); jg.writeStringField("rectag", actionData.rectag); jg.writeNumberField("type", actionData.type); jg.writeNumberField("value", actionData.value); jg.writeEndObject(); jg.close(); } catch (IOException e) { e.printStackTrace(); } return sw.toString(); }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.organisational.TeamJSON.java
public final static void team2JSON(Team team, JsonGenerator jgenerator) throws IOException { jgenerator.writeStartObject();//from w ww.ja va 2 s .c o m jgenerator.writeNumberField(TEAM_ID, team.getId()); jgenerator.writeNumberField(TEAM_VERSION, team.getVersion()); jgenerator.writeStringField(TEAM_NAME, team.getName()); jgenerator.writeStringField(TEAM_DESCRIPTION, team.getDescription()); jgenerator.writeStringField(TEAM_COLOR_CODE, team.getColorCode()); jgenerator.writeArrayFieldStart(TEAM_OSI_ID); for (OSInstance osi : team.getOsInstances()) jgenerator.writeNumber(osi.getId()); jgenerator.writeEndArray(); jgenerator.writeArrayFieldStart(TEAM_APP_ID); for (Application app : team.getApplications()) jgenerator.writeNumber(app.getId()); jgenerator.writeEndArray(); jgenerator.writeEndObject(); }