Search in sources :

Example 1 with JSONWriter

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);
}
Also used : JSONWriter(org.noggit.JSONWriter) CharArr(org.noggit.CharArr)

Example 2 with JSONWriter

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);
}
Also used : JSONWriter(org.noggit.JSONWriter) CharArr(org.noggit.CharArr)

Example 3 with JSONWriter

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();
}
Also used : JSONWriter(org.noggit.JSONWriter) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) CharArr(org.noggit.CharArr)

Example 4 with JSONWriter

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();
}
Also used : JSONWriter(org.noggit.JSONWriter) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CharArr(org.noggit.CharArr) Test(org.junit.Test)

Example 5 with JSONWriter

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;
}
Also used : JSONWriter(org.noggit.JSONWriter) ClusterState(org.apache.solr.common.cloud.ClusterState) DocCollection(org.apache.solr.common.cloud.DocCollection) CharArr(org.noggit.CharArr)

Aggregations

CharArr (org.noggit.CharArr)6 JSONWriter (org.noggit.JSONWriter)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 DocCollection (org.apache.solr.common.cloud.DocCollection)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 Test (org.junit.Test)1