Search in sources :

Example 21 with JsonParser

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

the class TestJDKSerializability method _copyJson.

protected void _copyJson(JsonFactory f, String json, JsonGenerator g) throws IOException {
    JsonParser p = f.createParser(json);
    while (p.nextToken() != null) {
        g.copyCurrentEvent(p);
    }
    p.close();
    g.close();
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 22 with JsonParser

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

the class TestJDKSerializability method testParseException.

public void testParseException() throws Exception {
    JsonFactory jf = new JsonFactory();
    JsonParser p = jf.createParser("  { garbage! }");
    JsonParseException exc = null;
    try {
        p.nextToken();
        p.nextToken();
        fail("Should not get here");
    } catch (JsonParseException e) {
        exc = e;
    }
    p.close();
    byte[] stuff = jdkSerialize(exc);
    JsonParseException result = jdkDeserialize(stuff);
    assertNotNull(result);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 23 with JsonParser

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

the class ExceptionSerializationTest method testSimpleOther.

// to double-check [databind#1413]
public void testSimpleOther() throws Exception {
    JsonParser p = MAPPER.getFactory().createParser("{ }");
    InvalidFormatException exc = InvalidFormatException.from(p, "Test", getClass(), String.class);
    String json = MAPPER.writeValueAsString(exc);
    p.close();
    assertNotNull(json);
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 24 with JsonParser

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

the class TestPipeline method convertToArgs.

public static String[] convertToArgs(PipelineOptions options) {
    try {
        byte[] opts = MAPPER.writeValueAsBytes(options);
        JsonParser jsonParser = MAPPER.getFactory().createParser(opts);
        TreeNode node = jsonParser.readValueAsTree();
        ObjectNode optsNode = (ObjectNode) node.get("options");
        ArrayList<String> optArrayList = new ArrayList<>();
        Iterator<Entry<String, JsonNode>> entries = optsNode.fields();
        while (entries.hasNext()) {
            Entry<String, JsonNode> entry = entries.next();
            if (entry.getValue().isNull()) {
                continue;
            } else if (entry.getValue().isTextual()) {
                optArrayList.add("--" + entry.getKey() + "=" + entry.getValue().asText());
            } else {
                optArrayList.add("--" + entry.getKey() + "=" + entry.getValue());
            }
        }
        return optArrayList.toArray(new String[optArrayList.size()]);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Entry(java.util.Map.Entry) TreeNode(com.fasterxml.jackson.core.TreeNode) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 25 with JsonParser

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

the class JsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(String actualJson, Description description) {
    try {
        JsonFactory factory = MAPPER.getFactory();
        JsonParser jsonParser = factory.createParser(String.format(expectedJson));
        JsonNode expectedObject = MAPPER.readTree(jsonParser);
        jsonParser = factory.createParser(actualJson);
        JsonNode actualObject = MAPPER.readTree(jsonParser);
        if (!matchJsonObjects("/", expectedObject, actualObject, description)) {
            description.appendText(String.format(" in <%s>", actualJson));
            return false;
        }
    } catch (IOException e) {
        description.appendText(String.format("could not parse the following into a json object: <%s>", actualJson));
        return false;
    }
    return true;
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) 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)38 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