use of com.hazelcast.internal.json.ParseException in project hazelcast by hazelcast.
the class JsonParser_Test method parse_failsOnTooDeeplyNestedObject.
@Test
public void parse_failsOnTooDeeplyNestedObject() {
JsonObject object = new JsonObject();
for (int i = 0; i < 1001; i++) {
object = new JsonObject().add("foo", object);
}
final String input = object.toString();
ParseException exception = assertException(ParseException.class, new RunnableEx() {
public void run() throws IOException {
parser.parse(input);
}
});
assertEquals("Nesting too deep at 1:7002", exception.getMessage());
}
use of com.hazelcast.internal.json.ParseException 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());
}
use of com.hazelcast.internal.json.ParseException in project hazelcast by hazelcast.
the class JsonSchemaHelper method findValueWithPattern.
/**
* Extract the JsonValue that is stored in attributePath in input.
* This method validates expectedPattern using attributePath while
* extraction. If expectedPattern points to invalid or wrong attributes
* at any point, this method returns {@code null}
*
* NOTE: this method cannot handle patterns with "any" in it.
*
* @param input a byte array containing the target object
* @param schemaNode valid schema description to the target
* object. The behavior is undefined if
* description does not match the actual
* object
* @param expectedPattern this cannot contain "any"
* @param attributePath this cannot contain "any"
* @return JsonValue extracted or null
*/
@SuppressWarnings("checkstyle:npathcomplexity")
public static JsonValue findValueWithPattern(NavigableJsonInputAdapter input, JsonSchemaNode schemaNode, JsonPattern expectedPattern, JsonPathCursor attributePath) throws IOException {
for (int i = 0; i < expectedPattern.depth(); i++) {
if (attributePath.getNext() == null) {
return null;
}
if (schemaNode.isTerminal()) {
return null;
}
int expectedOrderIndex = expectedPattern.get(i);
JsonSchemaStructNode structDescription = (JsonSchemaStructNode) schemaNode;
if (structDescription.getChildCount() <= expectedOrderIndex) {
return null;
}
JsonSchemaNameValue nameValue = structDescription.getChild(expectedOrderIndex);
if (structMatches(input, nameValue, expectedOrderIndex, attributePath)) {
schemaNode = nameValue.getValue();
} else {
return null;
}
}
if (attributePath.getNext() == null) {
if (schemaNode.isTerminal()) {
// Otherwise, let the exceptions propagate
try {
JsonReducedValueParser valueParser = new JsonReducedValueParser();
int valuePos = ((JsonSchemaTerminalNode) schemaNode).getValueStartLocation();
return input.parseValue(valueParser, valuePos);
} catch (ParseException parseException) {
throw new HazelcastException(parseException);
}
} else {
return NonTerminalJsonValue.INSTANCE;
}
}
return null;
}
use of com.hazelcast.internal.json.ParseException in project hazelcast by hazelcast.
the class ManagementCenterServiceIntegrationTest method testTimedMemberState_returnsNotNull.
@Test
public void testTimedMemberState_returnsNotNull() {
String responseString = mcs.getTimedMemberStateJson().orElse(null);
assertFalse(isNullOrEmpty(responseString));
JsonObject object;
try {
object = Json.parse(responseString).asObject();
} catch (ParseException e) {
throw new AssertionError("Failed to parse JSON: " + responseString);
}
TimedMemberState memberState = new TimedMemberState();
memberState.fromJson(object.get("timedMemberState").asObject());
assertEquals(CLUSTER_NAME, memberState.getClusterName());
}
use of com.hazelcast.internal.json.ParseException in project hazelcast by hazelcast.
the class JsonParser_Test method parse_reader_rejectsEmpty.
@Test
public void parse_reader_rejectsEmpty() {
ParseException exception = assertException(ParseException.class, new RunnableEx() {
public void run() throws IOException {
parser.parse(new StringReader(""));
}
});
assertEquals(0, exception.getLocation().offset);
assertThat(exception.getMessage(), startsWith("Unexpected end of input at"));
}
Aggregations