Search in sources :

Example 26 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class JsonParser_Test method parse_failsOnTooDeeplyNestedMixedObject.

@Test
public void parse_failsOnTooDeeplyNestedMixedObject() {
    JsonValue value = new JsonObject();
    for (int i = 0; i < 1001; i++) {
        value = i % 2 == 0 ? new JsonArray().add(value) : new JsonObject().add("foo", value);
    }
    final String input = value.toString();
    ParseException exception = assertException(ParseException.class, new RunnableEx() {

        public void run() throws IOException {
            parser.parse(input);
        }
    });
    assertEquals("Nesting too deep at 1:4002", exception.getMessage());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) RunnableEx(com.hazelcast.internal.json.TestUtil.RunnableEx) ParseException(com.hazelcast.internal.json.ParseException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class Json_Test method array_long.

@Test
public void array_long() {
    assertEquals(new JsonArray().add(23l), Json.array(new long[] { 23l }));
    assertEquals(new JsonArray().add(23l).add(42l), Json.array(new long[] { 23l, 42l }));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class PrettyPrint_Test method testIndentWithSpaces_nestedArray.

@Test
public void testIndentWithSpaces_nestedArray() throws IOException {
    new JsonArray().add(23).add(new JsonArray().add(42)).writeTo(output, indentWithSpaces(2));
    assertEquals("[\n  23,\n  [\n    42\n  ]\n]", output.toString());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class PrettyPrint_Test method testIndentWithTabs.

@Test
public void testIndentWithTabs() throws IOException {
    new JsonArray().add(23).add(42).writeTo(output, indentWithTabs());
    assertEquals("[\n\t23,\n\t42\n]", output.toString());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 30 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class GcpComputeApi method zones.

List<String> zones(String project, String region, String accessToken) {
    String url = String.format("%s/compute/v1/projects/%s/regions/%s?alt=json&fields=zones", endpoint, project, region);
    String response = RestClient.create(url).withHeader("Authorization", String.format("OAuth %s", accessToken)).get().getBody();
    JsonArray zoneUrls = toJsonArray(Json.parse(response).asObject().get("zones"));
    List<String> zones = new ArrayList<>();
    for (JsonValue value : zoneUrls) {
        zones.add(lastPartOf(value.asString(), "/"));
    }
    return zones;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue)

Aggregations

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3