@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void exportData(HttpServletResponse resp, Principal prin) throws IOException { resp.setContentType(MediaType.APPLICATION_JSON_VALUE); // this writer puts things out onto the wire JsonWriter writer = new JsonWriter(resp.getWriter()); writer.setIndent(" "); try { writer.beginObject(); writer.name("exported-at"); writer.value(dateFormat.format(new Date())); writer.name("exported-from"); writer.value(config.getIssuer()); writer.name("exported-by"); writer.value(prin.getName()); // delegate to the service to do the actual export dataService_1_3.exportData(writer); writer.endObject(); // end root writer.close(); } catch (IOException e) { logger.error("Unable to export data", e); } }
@Override public void write(JsonWriter out, JsonElement value) throws IOException { if (value == null || value.isJsonNull()) { out.nullValue(); } else if (value.isJsonPrimitive()) { JsonPrimitive primitive = value.getAsJsonPrimitive(); if (primitive.isNumber()) { out.value(primitive.getAsNumber()); } else if (primitive.isBoolean()) { out.value(primitive.getAsBoolean()); } else { out.value(primitive.getAsString()); } } else if (value.isJsonArray()) { out.beginArray(); for (JsonElement e : value.getAsJsonArray()) { write(out, e); } out.endArray(); } else if (value.isJsonObject()) { out.beginObject(); for (Map.Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) { out.name(e.getKey()); write(out, e.getValue()); } out.endObject(); } else { throw new IllegalArgumentException("Couldn't write " + value.getClass()); } }
private void write(JsonWriter writer) throws IOException { writer.beginObject(); writer.name("public_key"); writer.value(getPubEncoded()); writer.name("private_key"); writer.value(getPrivEncoded()); writer.endObject(); }
@Override public void write(JsonWriter out, Classification value) throws IOException { if (isNullToEmptyWriting() && value == null) { // option out.value(""); } else { // mainly here out.value(value != null ? value.code() : null); } }
@Override public void write(JsonWriter writer, Student student) throws IOException { writer.beginObject(); writer.name("name"); writer.value(student.getName()); writer.name("rollNo"); writer.value(student.getRollNo()); writer.endObject(); }
@Override public void write(final JsonWriter jsonWriter, final SibOne sibOne) throws IOException { jsonWriter.beginObject(); jsonWriter.name("sibone"); jsonWriter.value(sibOne.getName()); jsonWriter.name("sibtwo"); jsonWriter.value(sibOne.getPair().getName()); jsonWriter.endObject(); }
/* * (non-Javadoc) * * @see com.google.gson.TypeAdapter#write(com.google.gson.stream.JsonWriter, java.lang.Object) */ @Override public void write(JsonWriter writer, SpeechTimestamp speechTimestamp) throws IOException { writer.beginArray(); writer.value(speechTimestamp.getWord()); writer.value(speechTimestamp.getStartTime()); writer.value(speechTimestamp.getEndTime()); writer.endArray(); writer.flush(); }
@Override public void write(JsonWriter out, Double value) throws IOException { if (value == null) { out.nullValue(); return; } if (Double.isNaN(value)) { out.value("NaN"); return; } out.value(value); }
public void write(JsonWriter jsonWriter, Number number) throws IOException { if (number == null) { jsonWriter.nullValue(); } else { jsonWriter.value(number.toString()); } }
@Override public void write(JsonWriter out, QblECPublicKey value) throws IOException { out.beginObject(); out.name("public_key"); out.value(Hex.toHexString(value.getKey())); out.endObject(); }
@Override public void write(JsonWriter out, LocalDate date) throws IOException { if (date == null) { out.nullValue(); } else { out.value(formatter.print(date)); } }
public void write(JsonWriter jsonWriter, Number number) throws IOException { if (number == null) { jsonWriter.nullValue(); return; } Gson.this.checkValidFloatingPoint(number.doubleValue()); jsonWriter.value(number); }
@Override public void write(JsonWriter out, Boolean value) throws IOException { if (value == null) { out.nullValue(); return; } out.value(value); }
@Override public void write(JsonWriter out, AccessType value) throws IOException { if (value == null) { out.nullValue(); } else { out.value(value.getValue()); } }
@Override public synchronized void write(JsonWriter out, Date value) throws IOException { if (value == null) { out.nullValue(); return; } String dateFormatAsString = iso8601Format.format(value); out.value(dateFormatAsString); }
public File executeQuery(String command, String rootDirectory) throws SQLException, IOException { Statement stmt = null; if (this.conn != null) { final String fileName = UUID.randomUUID().toString(); final File file = File.createTempFile(fileName, ".json"); try { stmt = this.conn.createStatement(); ResultSet results = stmt.executeQuery(command); ResultSetMetaData rsmd = results.getMetaData(); // Borrowed from // http://stackoverflow.com/questions/18960446/how-to-convert-a-java-resultset-into-json JsonWriter writer = new JsonWriter(new PrintWriter(file)); int count = 0; int numRows = 0; boolean hasRows = results.last(); if (hasRows) { numRows = results.getRow(); } results.beforeFirst(); writer.beginObject(); writer.name("elements"); writer.beginArray(); while (results.next()) { writer.beginObject(); for (int idx = 1; idx <= rsmd.getColumnCount(); idx++) { writer.name(rsmd.getColumnLabel(idx)); writer.value(results.getString(idx)); } writer.endObject(); count++; } if (count == 0) { writer.beginObject(); writer.endObject(); } writer.endArray(); writer.endObject(); writer.flush(); writer.close(); return file; } catch (SQLException e) { e.printStackTrace(); return null; } finally { if (stmt != null) { stmt.close(); } } } return null; }
@Override public void write(JsonWriter jsonWriter, Date date) throws IOException { if (date == null) { jsonWriter.nullValue(); return; } SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); jsonWriter.value(dateFormat.format(date)); }
@Override protected void writeValues(JsonWriter writer, StringFilter value) throws IOException { super.writeValues(writer, value); writer.name(JsonValues.patterns.name()); List<Pattern> patterns = ((StringFilter.PatternList) value).getPatterns(); writer.beginArray(); for (Pattern pattern : patterns) { writer.value(pattern.pattern()); } writer.endArray(); }
@Override public void writeJson(@NotNull JsonWriter w) throws IOException { w.name(NAME); w.beginObject(); w.name("CacheCodes"); w.beginArray(); for (String cache : caches) { if (cache != null && !cache.isEmpty()) w.value(cache); } w.endArray(); w.endObject(); }
public void write(JsonWriter paramJsonWriter, Date paramDate) throws IOException { if (paramDate == null) ; try { paramJsonWriter.nullValue(); while (true) { return; paramJsonWriter.value(this.enUsFormat.format(paramDate)); } } finally { } throw paramJsonWriter; }
@Override public void write(JsonWriter writer, Binding binding) throws IOException { if (binding == null) { writer.nullValue(); return; } writer.beginObject(); if (binding.getIndex() != null) { writer.name("index"); writer.value(binding.getIndex()); } if (binding.getTypeOfValue() != null) { writer.name("type"); writer.value(binding.getTypeOfValue().name()); } if (binding.getValue() != null) { writer.name("value"); if (binding.getValue() instanceof Number) { writer.value((Number) binding.getValue()); } else if (binding.getValue() instanceof String) { writer.value((String) binding.getValue()); } else if (binding.getValue() instanceof Boolean) { writer.value((Boolean) binding.getValue()); } else { writer.value(GsonUtils.newGson().toJson(binding.getValue())); } } writer.endObject(); }
private static void write(JsonWriter jsonwriter, Calendar calendar) throws IOException { if (calendar == null) { jsonwriter.nullValue(); return; } else { jsonwriter.beginObject(); jsonwriter.name("year"); jsonwriter.value(calendar.get(1)); jsonwriter.name("month"); jsonwriter.value(calendar.get(2)); jsonwriter.name("dayOfMonth"); jsonwriter.value(calendar.get(5)); jsonwriter.name("hourOfDay"); jsonwriter.value(calendar.get(11)); jsonwriter.name("minute"); jsonwriter.value(calendar.get(12)); jsonwriter.name("second"); jsonwriter.value(calendar.get(13)); jsonwriter.endObject(); return; } }
public void write(JsonWriter out, BitSet src) throws IOException { if (src == null) { out.nullValue(); return; } out.beginArray(); for (int i = 0; i < src.length(); i++) { int value = (src.get(i)) ? 1 : 0; out.value(value); } out.endArray(); }
private void writeQuestList( JsonWriter out, List<Quest> quests, List<Quest> setQuests, String name) throws IOException { List<Quest> inSetQuests = new ArrayList<>(setQuests); inSetQuests.retainAll(quests); if (!inSetQuests.isEmpty()) { out.name(name).beginArray(); for (Quest quest : inSetQuests) { int index = setQuests.indexOf(quest); if (index != -1) { out.value(index); } } out.endArray(); } }
@Override public void write(JsonWriter out, Calendar value) throws IOException { if (value == null) { out.nullValue(); return; } out.beginObject(); out.name(YEAR); out.value(value.get(Calendar.YEAR)); out.name(MONTH); out.value(value.get(Calendar.MONTH)); out.name(DAY_OF_MONTH); out.value(value.get(Calendar.DAY_OF_MONTH)); out.name(HOUR_OF_DAY); out.value(value.get(Calendar.HOUR_OF_DAY)); out.name(MINUTE); out.value(value.get(Calendar.MINUTE)); out.name(SECOND); out.value(value.get(Calendar.SECOND)); out.endObject(); }
@Override public void write(JsonWriter out, InetAddress value) throws IOException { out.value(value == null ? null : value.getHostAddress()); }
public void write(JsonWriter jsonwriter, Number number) { jsonwriter.value(number); }
@Override public void write(JsonWriter out, Locale value) throws IOException { out.value(value == null ? null : value.toString()); }
/** * Serialize YangInstanceIdentifier with specified JsonWriter. * * @param writer JsonWriter * @param value YangInstanceIdentifier */ @Override public void serializeToWriter(final JsonWriter writer, final YangInstanceIdentifier value) throws IOException { writer.value(serialize(value)); }
public void write(JsonWriter out, T value) throws IOException { out.value(value == null ? null : constantToName.get(value)); }