@Nullable public static String newDocumentText(@NotNull final IpnbFilePanel ipnbPanel) { final IpnbFile ipnbFile = ipnbPanel.getIpnbFile(); if (ipnbFile == null) return null; for (IpnbEditablePanel panel : ipnbPanel.getIpnbPanels()) { if (panel.isModified()) { panel.updateCellSource(); } } final IpnbFileRaw fileRaw = new IpnbFileRaw(); fileRaw.metadata = ipnbFile.getMetadata(); if (ipnbFile.getNbformat() == 4) { for (IpnbCell cell : ipnbFile.getCells()) { fileRaw.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat())); } } else { final IpnbWorksheet worksheet = new IpnbWorksheet(); worksheet.cells.clear(); for (IpnbCell cell : ipnbFile.getCells()) { worksheet.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat())); } fileRaw.worksheets = new IpnbWorksheet[] {worksheet}; } final StringWriter stringWriter = new StringWriter(); final JsonWriter writer = new JsonWriter(stringWriter); writer.setIndent(" "); gson.toJson(fileRaw, fileRaw.getClass(), writer); return stringWriter.toString(); }
public void write(JsonWriter jsonWriter, Number number) throws IOException { if (number == null) { jsonWriter.nullValue(); } else { jsonWriter.value(number.toString()); } }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); try { SubjectDAO subdao = new SubjectDAO(); DatastreamDAO dstreamDao = new DatastreamDAO(); List<JsonSubject> jsubList = new ArrayList<JsonSubject>(); List<Subject> subList = new ArrayList<Subject>(); String loginID = "leoncool"; if (request.getParameter(AllConstants.api_entryPoints.request_api_loginid) != null) { loginID = request.getParameter(AllConstants.api_entryPoints.request_api_loginid); } UserDAO userDao = new UserDAO(); if (!userDao.existLogin(loginID)) { ReturnParser.outputErrorException( response, AllConstants.ErrorDictionary.Unauthorized_Access, null, null); return; } if (request.getParameter(AllConstants.api_entryPoints.request_api_onlyParentSubjects) != null && request .getParameter(AllConstants.api_entryPoints.request_api_onlyParentSubjects) .equalsIgnoreCase(AllConstants.api_entryPoints.request_api_true)) { subList = subdao.findOnlyParentSubjectsByLoginID(loginID); } else { subList = subdao.findSubjectsByLoginID(loginID); } DBtoJsonUtil dbtoJUtil = new DBtoJsonUtil(); for (Subject sub : subList) { if (sub.getVisibleSet() != null && sub.getVisibleSet().equalsIgnoreCase(AllConstants.ProgramConts.visibleSet_PUBLIC)) { jsubList.add(dbtoJUtil.convert_a_Subject(sub)); } } System.out.println(jsubList.size()); Gson gson = new Gson(); JsonElement je = gson.toJsonTree(jsubList); JsonObject jo = new JsonObject(); jo.addProperty(AllConstants.ProgramConts.result, AllConstants.ProgramConts.succeed); jo.add("subject_list", je); JsonWriter jwriter = new JsonWriter(response.getWriter()); // if (request.getParameter("callback") != null) { // System.out.println("using callback"); // out.print(request.getParameter("callback")+"("+ gson.toJson(jo) + ");"); // } else { // gson.toJson(jo, jwriter); // jwriter.close(); // } gson.toJson(jo, jwriter); jwriter.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { out.close(); } }
@Override public void write(JsonWriter out, Quest.ReputationReward value) throws IOException { out.beginObject(); out.name(REPUTATION).value(value.getReputation().getId()); out.name(VALUE).value(value.getValue()); out.endObject(); }
@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, Classification value) throws IOException { if (isNullToEmptyWriting() && value == null) { // option out.value(""); } else { // mainly here out.value(value != null ? value.code() : null); } }
@Override protected void writeValues(JsonWriter writer, StringFilter value) throws IOException { super.writeValues(writer, value); writer.name(JsonValues.rule.name()).value(((StringFilter.FilterSet) value).getRule().name()); writer.name(JsonValues.set.name()); List<StringFilter> set = ((StringFilter.FilterSet) value).getSet(); GSON.toJson(set, set.getClass(), writer); }
@Override public void write(JsonWriter out, LocalDate date) throws IOException { if (date == null) { out.nullValue(); } else { out.value(formatter.print(date)); } }
@Override public void write(JsonWriter out, AccessType value) throws IOException { if (value == null) { out.nullValue(); } else { out.value(value.getValue()); } }
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); }
private void pushWriter(ByteArrayOutputStream baos) { OutputStreamWriter osw = new OutputStreamWriter(baos, Charsets.UTF_8); JsonWriter writer = new JsonWriter(osw); writer.setIndent(" "); // two spaces WriterByteArrayOutputStream wbaos = new WriterByteArrayOutputStream(writer, baos); writers.push(wbaos); }
@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); }
@Override public void writeJson(JsonWriter writer) throws IOException { writer.name(getKey()); writer.beginObject(); for (Map.Entry<String, String> jsonPair : _value.entrySet()) { writer.name(jsonPair.getKey()).value(jsonPair.getValue()); } writer.endObject(); }
@Override public void write(JsonWriter out, RepeatInfo value) throws IOException { out.beginObject(); out.name(TYPE).value(value.getType().name()); if (value.getType().isUseTime()) { out.name(DAYS).value(value.getDays()); out.name(HOURS).value(value.getHours()); } out.endObject(); }
@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 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()); } }
public void writeJson(JsonWriter writer) throws IOException { if (messageParts.size() == 1) { latest().writeJson(writer); } else { writer.beginObject().name("text").value("").name("extra").beginArray(); for (final MessagePart part : this) { part.writeJson(writer); } writer.endArray().endObject(); } }
@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(); }
private JsonWriter newJsonWriter(Writer writer) throws IOException { if (this.generateNonExecutableJson) { writer.write(JSON_NON_EXECUTABLE_PREFIX); } JsonWriter jsonWriter = new JsonWriter(writer); if (this.prettyPrinting) { jsonWriter.setIndent(" "); } jsonWriter.setSerializeNulls(this.serializeNulls); return jsonWriter; }
@Override public void write(JsonWriter out, QuestSet value) throws IOException { out.beginObject(); out.name(NAME).value(value.getName()); out.name(DESCRIPTION).value(value.getDescription()); out.name(QUESTS).beginArray(); for (Quest quest : value.getQuests()) { QUEST_ADAPTER.write(out, quest); } out.endArray().endObject(); }
public void write(JsonWriter out, Collection<E> collection) throws IOException { if (collection == null) { out.nullValue(); // TODO: better policy here? return; } out.beginArray(); for (E element : collection) { elementTypeAdapter.write(out, element); } out.endArray(); }
@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); }
/** * {@inheritDoc} * * @see com.google.gson.TypeAdapter#write(com.google.gson.stream.JsonWriter, java.lang.Object) */ @Override public void write(final JsonWriter out, final RestQueryRow value) throws IOException { out.beginObject(); if (value.getValues() == null || value.getValues().length == 0) return; out.name(RestQueryRow.ROW_LABEL); BUILDER.toJson(value.getValues(), String[].class, out); out.endObject(); }
private void writeItemStackArray(JsonWriter out, ItemStack[] stacks, String name) throws IOException { if (stacks != null) { out.name(name).beginArray(); for (ItemStack stack : stacks) { if (stack != null) { MinecraftAdapter.ITEM_STACK.write(out, stack); } } out.endArray(); } }
public void write(JsonWriter out, Map<K, V> value) throws IOException { if (value == null) { out.nullValue(); return; } out.beginObject(); for (Map.Entry<K, V> element : value.entrySet()) { out.name(String.valueOf(element.getKey())); valueAdapter.write(out, element.getValue()); } out.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 @Transactional public void exportEntities(ImportExportBlueprint blueprint, Writer writer) { try (JsonWriter jsonWriter = new JsonWriter(writer)) { jsonWriter.setIndent(" "); ExportContext exportContext = new ExportContext(sortBlueprintRecords(blueprint), bundleContext, allEntities); ExportWriter exportWriter = new ExportWriter(jsonWriter, exportContext); exportWriter.export(); } catch (IOException e) { throw new ImportExportException("An IO error occurred during export.", e); } }
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(); }
/** * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link * JsonWriter}. This JSON should be compatible with vanilla formatter commands such as {@code * /tellraw}. * * @return The JSON string representing this object. */ public String toJSONString() { if (!dirty && jsonString != null) { return jsonString; } StringWriter string = new StringWriter(); JsonWriter json = new JsonWriter(string); try { writeJson(json); json.close(); } catch (Exception e) { throw new RuntimeException("invalid message"); } jsonString = string.toString(); dirty = false; return jsonString; }