use of org.noggit.JSONWriter in project disgear by yangbutao.
the class ZkStateReader method toJSON.
public static byte[] toJSON(Object o) {
CharArr out = new CharArr();
// indentation by default
new JSONWriter(out, 2).write(o);
return toUTF8(out);
}
use of org.noggit.JSONWriter in project lucene-solr by apache.
the class Utils method toJSON.
public static byte[] toJSON(Object o) {
if (o == null)
return new byte[0];
CharArr out = new CharArr();
// indentation by default
new JSONWriter(out, 2).write(o);
return toUTF8(out);
}
use of org.noggit.JSONWriter in project lucene-solr by apache.
the class TestDelegationTokenResponse method getNestedMapJson.
private String getNestedMapJson(String outerKey, String innerKey, Object innerValue) {
CharArr out = new CharArr();
JSONWriter w = new JSONWriter(out, 2);
Map<String, Object> innerMap = new HashMap<String, Object>();
innerMap.put(innerKey, innerValue);
Map<String, Map<String, Object>> outerMap = new HashMap<String, Map<String, Object>>();
outerMap.put(outerKey, innerMap);
w.write(outerMap);
return out.toString();
}
use of org.noggit.JSONWriter in project lucene-solr by apache.
the class SmileWriterTest method testTypes.
@Test
public void testTypes() throws IOException {
SolrQueryRequest req = req("dummy");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("data1", Float.NaN);
rsp.add("data2", Double.NEGATIVE_INFINITY);
rsp.add("data3", Float.POSITIVE_INFINITY);
SmileResponseWriter smileResponseWriter = new SmileResponseWriter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
smileResponseWriter.write(baos, req, rsp);
Map m = (Map) decodeSmile(new ByteArrayInputStream(baos.toByteArray()));
CharArr out = new CharArr();
JSONWriter jsonWriter = new JSONWriter(out, 2);
// indentation by default
jsonWriter.setIndentSize(-1);
jsonWriter.write(m);
String s = new String(Utils.toUTF8(out), StandardCharsets.UTF_8);
assertEquals(s, "{\"data1\":NaN,\"data2\":-Infinity,\"data3\":Infinity}");
req.close();
}
use of org.noggit.JSONWriter in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method printClusterStateInfo.
protected String printClusterStateInfo(String collection) throws Exception {
cloudClient.getZkStateReader().forceUpdateCollection(collection);
String cs = null;
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
if (collection != null) {
cs = clusterState.getCollection(collection).toString();
} else {
Map<String, DocCollection> map = clusterState.getCollectionsMap();
CharArr out = new CharArr();
new JSONWriter(out, 2).write(map);
cs = out.toString();
}
return cs;
}
Aggregations