Search in sources :

Example 66 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project dcos-commons by mesosphere.

the class DefaultServiceSpecTest method invalidTaskName.

@Test
public void invalidTaskName() throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("invalid-task-name.yml").getFile());
    try {
        DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();
        Assert.fail("Expected exception");
    } catch (JsonMappingException e) {
        Assert.assertTrue(e.getCause().toString(), e.getCause() instanceof JsonParseException);
        JsonParseException cause = (JsonParseException) e.getCause();
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Duplicate field 'meta-data-task'"));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) File(java.io.File) Test(org.junit.Test)

Example 67 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project navajo by Dexels.

the class ServletArticleRuntimeImpl method commit.

@Override
public void commit() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode;
    try {
        rootNode = mapper.readValue(writer.toString(), JsonNode.class);
    } catch (JsonParseException e) {
        logger.error("JSON parse error: ", e);
        response.getWriter().write("Invalid JSON follows:\n");
        response.getWriter().write(writer.toString());
        return;
    }
    ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
    writer.writeValue(response.getWriter(), rootNode);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 68 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project elasticsearch by elastic.

the class BaseXContentTestCase method testChecksForDuplicates.

public void testChecksForDuplicates() throws Exception {
    assumeTrue("Test only makes sense if XContent parser has strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
    XContentBuilder builder = builder().startObject().field("key", 1).field("key", 2).endObject();
    JsonParseException pex = expectThrows(JsonParseException.class, () -> createParser(builder).map());
    assertThat(pex.getMessage(), startsWith("Duplicate field 'key'"));
}
Also used : JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 69 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project elasticsearch by elastic.

the class FunctionScoreQueryBuilderTests method testMalformedThrowsException.

public void testMalformedThrowsException() throws IOException {
    String json = "{\n" + "    \"function_score\":{\n" + "        \"query\":{\n" + "            \"term\":{\n" + "                \"name.last\":\"banon\"\n" + "            }\n" + "        },\n" + "        \"functions\": [\n" + "            {\n" + "                {\n" + "            }\n" + "        ]\n" + "    }\n" + "}";
    JsonParseException e = expectThrows(JsonParseException.class, () -> parseQuery(json));
    assertThat(e.getMessage(), containsString("Unexpected character ('{"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 70 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.

the class ParserErrorHandlingTest method _testMangledNumbers.

private void _testMangledNumbers(int mode) throws Exception {
    String doc = "123true";
    JsonParser p = createParser(mode, doc);
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
    // Also test with floats
    doc = "1.5false";
    p = createParser(mode, doc);
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)145 IOException (java.io.IOException)75 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)58 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 JsonParser (com.fasterxml.jackson.core.JsonParser)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 Map (java.util.Map)19 JsonToken (com.fasterxml.jackson.core.JsonToken)15 InputStream (java.io.InputStream)15 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 File (java.io.File)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonFactory (com.fasterxml.jackson.core.JsonFactory)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5