Search in sources :

Example 51 with JsonParser

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

the class ParserErrorHandlingTest method _testMangledNumbersFloat.

private void _testMangledNumbersFloat(int mode) throws Exception {
    // Also test with floats
    JsonParser p = createParser(mode, "1.5false");
    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)

Example 52 with JsonParser

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

the class ParserErrorHandlingTest method _testMangledNumbersInt.

private void _testMangledNumbersInt(int mode) throws Exception {
    JsonParser p = createParser(mode, "123true");
    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)

Example 53 with JsonParser

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

the class Surrogate223Test method testSurrogatesByteBacked.

// for [core#223]
public void testSurrogatesByteBacked() throws Exception {
    ByteArrayOutputStream out;
    JsonGenerator g;
    final String toQuote = new String(Character.toChars(0x1F602));
    // just sanity check
    assertEquals(2, toQuote.length());
    // default should be disabled:
    // assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
    out = new ByteArrayOutputStream();
    g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
    g.writeStartArray();
    g.writeString(toQuote);
    g.writeEndArray();
    g.close();
    // brackets, quotes, 4-byte encoding
    assertEquals(2 + 2 + 4, out.size());
    // Also parse back to ensure correctness
    JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toByteArray());
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    p.close();
    // but may revert back to original behavior
    out = new ByteArrayOutputStream();
    g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
    // g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
    g.writeStartArray();
    g.writeString(toQuote);
    g.writeEndArray();
    g.close();
    // brackets, quotes, 2 x 6 byte JSON escape
    assertEquals(2 + 2 + 12, out.size());
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 54 with JsonParser

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

the class Surrogate223Test method testSurrogatesCharBacked.

// for [core#223]
public void testSurrogatesCharBacked() throws Exception {
    Writer out;
    JsonGenerator g;
    final String toQuote = new String(Character.toChars(0x1F602));
    // just sanity check
    assertEquals(2, toQuote.length());
    // default should be disabled:
    // assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
    out = new StringWriter();
    g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
    g.writeStartArray();
    g.writeString(toQuote);
    g.writeEndArray();
    g.close();
    // brackets, quotes, 2 chars as is
    assertEquals(2 + 2 + 2, out.toString().length());
    // Also parse back to ensure correctness
    JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), out.toString());
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    p.close();
    // but may revert back to original behavior
    out = new StringWriter();
    g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
    // g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
    g.writeStartArray();
    g.writeString(toQuote);
    g.writeEndArray();
    g.close();
    // brackets, quotes, 2 x 6 byte JSON escape
    assertEquals(2 + 2 + 12, out.toString().length());
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 55 with JsonParser

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

the class TestParserOverrides method _testTokenAccess.

/*
    /**********************************************************
    /* Actual test methods
    /**********************************************************
     */
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception {
    final String DOC = "[ ]";
    JsonParser jp = useStream ? jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8"))) : jf.createParser(ObjectReadContext.empty(), DOC);
    assertNull(jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    assertNull(jp.getEmbeddedObject());
    assertToken(JsonToken.START_ARRAY, jp.nextToken());
    assertToken(JsonToken.START_ARRAY, jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    // Also: no codec defined by default
    try {
        jp.readValueAsTree();
        fail("Should get exception without codec");
    } catch (UnsupportedOperationException e) {
        verifyException(e, "Operation not supported");
    }
    jp.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)587 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)171 IOException (java.io.IOException)126 JsonFactory (com.fasterxml.jackson.core.JsonFactory)76 Test (org.junit.Test)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)51 JsonNode (com.fasterxml.jackson.databind.JsonNode)46 HashSet (java.util.HashSet)43 JsonToken (com.fasterxml.jackson.core.JsonToken)41 LinkedHashSet (java.util.LinkedHashSet)39 HashMap (java.util.HashMap)35 LinkedList (java.util.LinkedList)26 JsonParseException (com.fasterxml.jackson.core.JsonParseException)23 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)21 List (java.util.List)21 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)20 InputStream (java.io.InputStream)20