Search in sources :

Example 31 with JsonFactory

use of org.codehaus.jackson.JsonFactory in project neo4j by neo4j.

the class RowWriterTests method shouldWriteNestedMaps.

@Test
public void shouldWriteNestedMaps() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator json = new JsonFactory(new Neo4jJsonCodec()).createJsonGenerator(out);
    JsonNode row = serialize(out, json, new RowWriter());
    MatcherAssert.assertThat(row.size(), equalTo(1));
    JsonNode firstCell = row.get(0);
    MatcherAssert.assertThat(firstCell.get("one").get("two").size(), is(2));
    MatcherAssert.assertThat(firstCell.get("one").get("two").get(0).asBoolean(), is(true));
    MatcherAssert.assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), is(42));
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonNode(org.codehaus.jackson.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 32 with JsonFactory

use of org.codehaus.jackson.JsonFactory in project pinpoint by naver.

the class ObjectMapper_1_x_IT method testConstructor.

@Test
public void testConstructor() throws Exception {
    ObjectMapper mapper1 = new ObjectMapper();
    ObjectMapper mapper2 = new ObjectMapper(new JsonFactory());
    Constructor<?> omConstructor1 = ObjectMapper.class.getConstructor();
    Constructor<?> omConstructor2 = ObjectMapper.class.getConstructor(JsonFactory.class);
    Constructor<?> omConstructor3 = ObjectMapper.class.getConstructor(JsonFactory.class, SerializerProvider.class, DeserializerProvider.class);
    Class<?> serializationConfig = null;
    Class<?> deserializationConfig = null;
    try {
        serializationConfig = Class.forName("org.codehaus.jackson.map.SerializationConfig");
        deserializationConfig = Class.forName("org.codehaus.jackson.map.DeserializationConfig");
    } catch (ClassNotFoundException ignored) {
    }
    Constructor<?> omConstructor4 = null;
    if (serializationConfig != null && deserializationConfig != null) {
        omConstructor4 = ObjectMapper.class.getConstructor(JsonFactory.class, SerializerProvider.class, DeserializerProvider.class, serializationConfig, deserializationConfig);
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    if (omConstructor4 != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, omConstructor4));
    }
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor3), event(SERVICE_TYPE, omConstructor1));
    if (omConstructor4 != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, omConstructor4));
    }
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor3), event(SERVICE_TYPE, omConstructor2));
    verifier.verifyTraceCount(0);
}
Also used : DeserializerProvider(org.codehaus.jackson.map.DeserializerProvider) JsonFactory(org.codehaus.jackson.JsonFactory) SerializerProvider(org.codehaus.jackson.map.SerializerProvider) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 33 with JsonFactory

use of org.codehaus.jackson.JsonFactory in project zaproxy by zaproxy.

the class HarUtils method createHarRequest.

public static HarRequest createHarRequest(String jsonHarRequest) throws IOException {
    HarRequest harRequest;
    try (JsonParser jp = new JsonFactory().createJsonParser(jsonHarRequest)) {
        jp.nextToken();
        jp.nextToken();
        harRequest = new HarRequest(jp, null);
    }
    return harRequest;
}
Also used : HarRequest(edu.umass.cs.benchlab.har.HarRequest) JsonFactory(org.codehaus.jackson.JsonFactory) JsonParser(org.codehaus.jackson.JsonParser)

Example 34 with JsonFactory

use of org.codehaus.jackson.JsonFactory in project flink by apache.

the class DumpCompiledPlanTest method dump.

private void dump(Plan p) {
    p.setExecutionConfig(new ExecutionConfig());
    try {
        OptimizedPlan op = compileNoStats(p);
        PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
        String json = dumper.getOptimizerPlanAsJSON(op);
        JsonParser parser = new JsonFactory().createJsonParser(json);
        while (parser.nextToken() != null) ;
    } catch (JsonParseException e) {
        e.printStackTrace();
        Assert.fail("JSON Generator produced malformatted output: " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("An error occurred in the test: " + e.getMessage());
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) JsonFactory(org.codehaus.jackson.JsonFactory) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) JsonParseException(org.codehaus.jackson.JsonParseException) JsonParseException(org.codehaus.jackson.JsonParseException) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) JsonParser(org.codehaus.jackson.JsonParser)

Example 35 with JsonFactory

use of org.codehaus.jackson.JsonFactory in project stanbol by apache.

the class AnalyzedTextSerializer method serialize.

/**
     * Serializes the parsed {@link AnalysedText} to the {@link OutputStream} by
     * using the {@link Charset}.
     * @param at the {@link AnalysedText} to serialize
     * @param out the {@link OutputStream} 
     * @param charset the {@link Charset}. UTF-8 is used as default if <code>null</code>
     * is parsed
     */
public void serialize(AnalysedText at, OutputStream out, Charset charset) throws IOException {
    if (at == null) {
        throw new IllegalArgumentException("The parsed AnalysedText MUST NOT be NULL!");
    }
    if (out == null) {
        throw new IllegalArgumentException("The parsed OutputStream MUST NOT be NULL");
    }
    if (charset == null) {
        charset = UTF8;
    }
    JsonFactory jsonFactory = mapper.getJsonFactory();
    JsonGenerator jg = jsonFactory.createJsonGenerator(new OutputStreamWriter(out, charset));
    jg.useDefaultPrettyPrinter();
    jg.writeStartObject();
    jg.writeArrayFieldStart("spans");
    jg.writeTree(writeSpan(at));
    for (Iterator<Span> it = at.getEnclosed(EnumSet.allOf(SpanTypeEnum.class)); it.hasNext(); ) {
        jg.writeTree(writeSpan(it.next()));
    }
    jg.writeEndArray();
    jg.writeEndObject();
    jg.close();
}
Also used : SpanTypeEnum(org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) OutputStreamWriter(java.io.OutputStreamWriter) Span(org.apache.stanbol.enhancer.nlp.model.Span)

Aggregations

JsonFactory (org.codehaus.jackson.JsonFactory)38 JsonGenerator (org.codehaus.jackson.JsonGenerator)15 JsonParser (org.codehaus.jackson.JsonParser)13 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)6 File (java.io.File)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 GenericRecord (org.apache.avro.generic.GenericRecord)4 JsonNode (org.codehaus.jackson.JsonNode)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)3 BufferedWriter (java.io.BufferedWriter)2 DataOutputStream (java.io.DataOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Date (java.util.Date)2 List (java.util.List)2