Java Code Examples for com.google.gson.stream.JsonWriter#beginArray()
The following examples show how to use
com.google.gson.stream.JsonWriter#beginArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: y.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public void a(JsonWriter jsonwriter, BitSet bitset) { if (bitset == null) { jsonwriter.nullValue(); return; } jsonwriter.beginArray(); int i = 0; while (i < bitset.length()) { int j; if (bitset.get(i)) { j = 1; } else { j = 0; } jsonwriter.value(j); i++; } jsonwriter.endArray(); }
Example 2
Source File: JsonLdSerializer.java From schemaorg-java with Apache License 2.0 | 6 votes |
@Override public void write(JsonWriter out, List<? extends Thing> values) throws IOException { // Convert property multimap in a concrete schema.org type into JSON key-value pairs if (values == null || values.isEmpty()) { out.nullValue(); return; } // Top level value should be a Thing object or an array of Thing objects. if (values.size() == 1) { writeObject(out, values.get(0), true /* isTopLevelObject */); } else { out.beginArray(); for (Thing value : values) { writeObject(out, value, true /* isTopLevelObject */); } out.endArray(); } }
Example 3
Source File: SpliceDoNotRetryIOExceptionWrapping.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
@Override public void write(JsonWriter out, StandardException value) throws IOException { out.beginObject(); out.name("severity").value(value.getErrorCode()); out.name("textMessage").value(value.getTextMessage()); out.name("sqlState").value(value.getSqlState()); out.name("messageId").value(value.getMessageId()); out.name("arguments"); Object[] args = value.getArguments(); if (args == null) out.nullValue(); else { out.beginArray(); for (Object o : value.getArguments()) { if (o instanceof String) { out.value((String) o); } } out.endArray(); } out.endObject(); }
Example 4
Source File: PositionsAdapter.java From geogson with Apache License 2.0 | 6 votes |
@Override public void write(JsonWriter out, Positions value) throws IOException { if (value == null) { out.nullValue(); } else { out.beginArray(); if (value instanceof SinglePosition) { SinglePosition sp = (SinglePosition) value; out.value(sp.lon()); out.value(sp.lat()); if (!Double.isNaN(sp.alt())) { out.value(sp.alt()); } } else { for (Positions child : value.children()) { write(out, child); } } out.endArray(); } }
Example 5
Source File: BaseCoordinatesTypeAdapter.java From mapbox-java with MIT License | 6 votes |
protected void writePointList(JsonWriter out, List<Double> value) throws IOException { if (value == null) { return; } out.beginArray(); // Unshift coordinates List<Double> unshiftedCoordinates = CoordinateShifterManager.getCoordinateShifter().unshiftPoint(value); out.value(GeoJsonUtils.trim(unshiftedCoordinates.get(0))); out.value(GeoJsonUtils.trim(unshiftedCoordinates.get(1))); // Includes altitude if (value.size() > 2) { out.value(unshiftedCoordinates.get(2)); } out.endArray(); }
Example 6
Source File: MCRRestAPIClassifications.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * output children in JSON format used as input for a jsTree * * @param eParent - the parent xml element * @param writer - the JSON writer * @param lang - the language to be filtered or null if all languages should be displayed * @param opened - true, if all leaf nodes should be displayed * @param disabled - true, if all nodes should be disabled * @param selected - true, if all node should be selected * * @throws IOException */ private static void writeChildrenAsJSONJSTree(Element eParent, JsonWriter writer, String lang, boolean opened, boolean disabled, boolean selected) throws IOException { writer.beginArray(); for (Element e : eParent.getChildren("category")) { writer.beginObject(); writer.name("id").value(e.getAttributeValue("ID")); for (Element eLabel : e.getChildren("label")) { if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.name("text").value(eLabel.getAttributeValue("text")); } } if (opened || disabled || selected) { writer.name("state"); writer.beginObject(); if (opened) { writer.name("opened").value(true); } if (disabled) { writer.name("disabled").value(true); } if (selected) { writer.name("selected").value(true); } writer.endObject(); } if (e.getChildren("category").size() > 0) { writer.name("children"); writeChildrenAsJSONJSTree(e, writer, lang, opened, disabled, selected); } writer.endObject(); } writer.endArray(); }
Example 7
Source File: ArrayTypeAdapter.java From gson with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void write(JsonWriter out, Object array) throws IOException { if (array == null) { out.nullValue(); return; } out.beginArray(); for (int i = 0, length = Array.getLength(array); i < length; i++) { E value = (E) Array.get(array, i); componentTypeAdapter.write(out, value); } out.endArray(); }
Example 8
Source File: TypeAdapters.java From gson with Apache License 2.0 | 5 votes |
@Override public void write(JsonWriter out, BitSet src) throws IOException { out.beginArray(); for (int i = 0, length = src.length(); i < length; i++) { int value = (src.get(i)) ? 1 : 0; out.value(value); } out.endArray(); }
Example 9
Source File: MixedStreamTest.java From gson with Apache License 2.0 | 5 votes |
public void testWriteMixedStreamed() throws IOException { Gson gson = new Gson(); StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(stringWriter); jsonWriter.beginArray(); jsonWriter.setIndent(" "); gson.toJson(BLUE_MUSTANG, Car.class, jsonWriter); gson.toJson(BLACK_BMW, Car.class, jsonWriter); gson.toJson(RED_MIATA, Car.class, jsonWriter); jsonWriter.endArray(); assertEquals(CARS_JSON, stringWriter.toString()); }
Example 10
Source File: DimensionProperty.java From ForgeHax with MIT License | 5 votes |
@Override public void serialize(JsonWriter writer) throws IOException { writer.beginArray(); for (DimensionType dimension : dimensions) { writer.value(dimension.getName()); } writer.endArray(); }
Example 11
Source File: MixedStreamTest.java From gson with Apache License 2.0 | 5 votes |
public void testWriteClosed() throws IOException { Gson gson = new Gson(); JsonWriter jsonWriter = new JsonWriter(new StringWriter()); jsonWriter.beginArray(); jsonWriter.endArray(); jsonWriter.close(); try { gson.toJson(BLUE_MUSTANG, Car.class, jsonWriter); fail(); } catch (IllegalStateException expected) { } }
Example 12
Source File: NMSRegistryDumper.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public void write(final JsonWriter out, final Vec3D vec) throws IOException { out.beginArray(); out.value(vec.x); out.value(vec.y); out.value(vec.z); out.endArray(); }
Example 13
Source File: GsonSmartyStreetsApiJsonParser.java From Smarty-Streets-AutoCompleteTextView with Apache License 2.0 | 5 votes |
@Override public void writeHistoryJson(final OutputStream os, final List<Address> addresses) throws JsonWritingException { try { JsonWriter writer = new JsonWriter(new OutputStreamWriter(os, "UTF-8")); writer.setIndent(" "); writer.beginArray(); for (Address address : addresses) { gson.toJson(address, Address.class, writer); } writer.endArray(); writer.close(); } catch (Exception e) { throw new JsonWritingException(e); } }
Example 14
Source File: NodeLayoutStore.java From olca-app with Mozilla Public License 2.0 | 5 votes |
private static void writeAsJson(List<NodeLayoutInfo> layoutInfo, File file) throws IOException { JsonWriter w = new JsonWriter(new FileWriter(file)); w.beginObject(); w.name("nodes"); w.beginArray(); for (NodeLayoutInfo layout : layoutInfo) writeAsJson(layout, w); w.endArray(); w.endObject(); w.flush(); w.close(); }
Example 15
Source File: DataRestResources.java From swellrt with Apache License 2.0 | 5 votes |
/** * Returns info about the wave. Just an example of JAX-RS usage. */ @GET @Path(WAVE_PATH) public Response wave(@PathParam(WAVE_ID) WaveId waveId) { JsonStreamingResponse response = new JsonStreamingResponse() { @Override public void write(JsonWriter jw) throws IOException { jw.beginObject(); jw.name("wavelets"); jw.beginArray(); try { for (WaveletId id : waveletProvider.getWaveletIds(waveId)) { jw.value(id.newSerialise()); } } catch (WaveServerException e) { e.printStackTrace(); } jw.endArray(); jw.endObject(); } }; return Response.status(200).entity(response).build(); }
Example 16
Source File: StreamAclJsonAdapter.java From esjc with MIT License | 5 votes |
private static void writeRoles(JsonWriter writer, String name, List<String> roles) throws IOException { if (roles != null) { writer.name(name); if (roles.size() == 1) { writer.value(roles.get(0)); } else { writer.beginArray(); for (String role : roles) { writer.value(role); } writer.endArray(); } } }
Example 17
Source File: TypeAdapters.java From gson with Apache License 2.0 | 5 votes |
@Override public void write(JsonWriter out, AtomicIntegerArray value) throws IOException { out.beginArray(); for (int i = 0, length = value.length(); i < length; i++) { out.value(value.get(i)); } out.endArray(); }
Example 18
Source File: ZooKeeperMigrator.java From localization_nifi with Apache License 2.0 | 4 votes |
void readZooKeeper(OutputStream zkData, AuthMode authMode, byte[] authData) throws IOException, KeeperException, InterruptedException, ExecutionException { ZooKeeper zooKeeper = getZooKeeper(zooKeeperEndpointConfig.getConnectString(), authMode, authData); JsonWriter jsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(zkData))); jsonWriter.setIndent(" "); JsonParser jsonParser = new JsonParser(); Gson gson = new GsonBuilder().create(); jsonWriter.beginArray(); // persist source ZooKeeperEndpointConfig gson.toJson(jsonParser.parse(gson.toJson(zooKeeperEndpointConfig)).getAsJsonObject(), jsonWriter); LOGGER.info("Retrieving data from source ZooKeeper: {}", zooKeeperEndpointConfig); final List<CompletableFuture<Void>> readFutures = streamPaths(getNode(zooKeeper, "/")) .parallel() .map(node -> CompletableFuture.supplyAsync(() -> { final DataStatAclNode dataStatAclNode = retrieveNode(zooKeeper, node); LOGGER.debug("retrieved node {} from {}", dataStatAclNode, zooKeeperEndpointConfig); return dataStatAclNode; }).thenAccept(dataStatAclNode -> { // persist each zookeeper node synchronized (jsonWriter) { gson.toJson(jsonParser.parse(gson.toJson(dataStatAclNode)).getAsJsonObject(), jsonWriter); } }) ).collect(Collectors.toList()); CompletableFuture<Void> allReadsFuture = CompletableFuture.allOf(readFutures.toArray(new CompletableFuture[readFutures.size()])); final CompletableFuture<List<Void>> finishedReads = allReadsFuture .thenApply(v -> readFutures.stream() .map(CompletableFuture::join) .collect(Collectors.toList())); final List<Void> readsDone = finishedReads.get(); jsonWriter.endArray(); jsonWriter.close(); if (LOGGER.isInfoEnabled()) { final int readCount = readsDone.size(); LOGGER.info("{} {} read from {}", readCount, readCount == 1 ? "node" : "nodes", zooKeeperEndpointConfig); } closeZooKeeper(zooKeeper); }
Example 19
Source File: MapTypeAdapterFactory.java From letv with Apache License 2.0 | 4 votes |
public void write(JsonWriter out, Map<K, V> map) throws IOException { if (map == null) { out.nullValue(); } else if (MapTypeAdapterFactory.this.complexMapKeySerialization) { boolean hasComplexKeys = false; List<JsonElement> keys = new ArrayList(map.size()); List<V> values = new ArrayList(map.size()); for (Entry<K, V> entry : map.entrySet()) { JsonElement keyElement = MapTypeAdapterFactory.toJsonTree(this.keyTypeAdapter, entry.getKey()); keys.add(keyElement); values.add(entry.getValue()); int i = (keyElement.isJsonArray() || keyElement.isJsonObject()) ? 1 : 0; hasComplexKeys |= i; } int i2; if (hasComplexKeys) { out.beginArray(); for (i2 = 0; i2 < keys.size(); i2++) { out.beginArray(); Streams.write((JsonElement) keys.get(i2), out); this.valueTypeAdapter.write(out, values.get(i2)); out.endArray(); } out.endArray(); return; } out.beginObject(); for (i2 = 0; i2 < keys.size(); i2++) { out.name(keyToString((JsonElement) keys.get(i2))); this.valueTypeAdapter.write(out, values.get(i2)); } out.endObject(); } else { out.beginObject(); for (Entry<K, V> entry2 : map.entrySet()) { out.name(String.valueOf(entry2.getKey())); this.valueTypeAdapter.write(out, entry2.getValue()); } out.endObject(); } }
Example 20
Source File: CatalogueExportRunner.java From TomboloDigitalConnector with MIT License | 3 votes |
public static void main(String[] args) throws Exception { runner.validateArguments(args); JsonWriter writer = new JsonWriter(runner.getOutputWriter(args[0])); List<Class<? extends Importer>> importers = runner.getImporterClasses(); writer.beginArray(); for (Class<? extends Importer> i : importers) { if (!i.getCanonicalName().equals("uk.org.tombolo.importer.generalcsv.GeneralCSVImporter") && !i.getCanonicalName().equals("uk.org.tombolo.importer.PythonImporter")) { Importer importer = runner.getImporter(i); List<String> datasources = runner.getDatasourceIds(importer); for (String d : datasources) { Datasource datasource = runner.getDatasource(d, importer); if (null != datasource.getDatasourceSpec()) datasource.writeJSON(writer); } } } writer.endArray(); writer.close(); }