Search in sources :

Example 96 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project dropwizard by dropwizard.

the class JacksonTest method objectMapperUsesGivenCustomJsonFactory.

@Test
void objectMapperUsesGivenCustomJsonFactory() {
    JsonFactory factory = Mockito.mock(JsonFactory.class);
    ObjectMapper mapper = Jackson.newObjectMapper(factory);
    assertThat(mapper.getFactory()).isSameAs(factory);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 97 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project pinpoint by naver.

the class ObjectMapperJDK7IT method testConstructor.

@Test
public void testConstructor() throws Exception {
    ObjectMapper mapper1 = new ObjectMapper();
    ObjectMapper mapper2 = new ObjectMapper(new JsonFactory());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Constructor<?> omConstructor = ObjectMapper.class.getConstructor(JsonFactory.class, DefaultSerializerProvider.class, DefaultDeserializationContext.class);
    Constructor<?> omConstructor1 = ObjectMapper.class.getConstructor();
    Constructor<?> omConstructor2 = ObjectMapper.class.getConstructor(JsonFactory.class);
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor1));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor2));
    verifier.verifyTraceCount(0);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 98 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project pinpoint by naver.

the class ObjectMapperIT method testConstructor.

@Test
public void testConstructor() throws Exception {
    ObjectMapper mapper1 = new ObjectMapper();
    ObjectMapper mapper2 = new ObjectMapper(new JsonFactory());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Constructor<?> omConstructor = ObjectMapper.class.getConstructor(JsonFactory.class, DefaultSerializerProvider.class, DefaultDeserializationContext.class);
    Constructor<?> omConstructor1 = ObjectMapper.class.getConstructor();
    Constructor<?> omConstructor2 = ObjectMapper.class.getConstructor(JsonFactory.class);
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor1));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor2));
    verifier.verifyTraceCount(0);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 99 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project pinpoint by naver.

the class AgentTimeHistogramTest method testViewModel.

@Test
public void testViewModel() throws IOException {
    Application app = new Application("test", ServiceType.STAND_ALONE);
    AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, Range.newRange(0, 1000 * 60));
    List<ResponseTime> responseHistogramList = createResponseTime(app, "test1", "test2");
    AgentTimeHistogram histogram = builder.build(responseHistogramList);
    List<AgentResponseTimeViewModel> viewModel = histogram.createViewModel(TimeHistogramFormat.V1);
    logger.debug("{}", viewModel);
    JsonFactory jsonFactory = mapper.getFactory();
    StringWriter stringWriter = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createGenerator(stringWriter);
    jsonGenerator.writeStartObject();
    for (AgentResponseTimeViewModel agentResponseTimeViewModel : viewModel) {
        jsonGenerator.writeObject(agentResponseTimeViewModel);
    }
    jsonGenerator.writeEndObject();
    jsonGenerator.flush();
    jsonGenerator.close();
    logger.debug(stringWriter.toString());
}
Also used : AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ResponseTime(com.navercorp.pinpoint.web.vo.ResponseTime) Application(com.navercorp.pinpoint.web.vo.Application) Test(org.junit.Test)

Example 100 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project pyramid by cheng-li.

the class VisualizerOld method getPositions.

private List<Integer> getPositions(Object docId, Object field, Object keywords, Object slop, Object in_order) throws IOException {
    System.out.println(docId + " " + field + " " + keywords + " " + slop + " " + in_order);
    final URL url = new URL("http://localhost:9200/ohsumed_20000/document/_search");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.addRequestProperty("Content-Type", "application/" + "POST");
    final String clauses = getJsonString(newSpanTerm((String) keywords, (String) field));
    final String body = "{\"explain\":\"false\"," + "                              \"query\":{" + "                                  \"filtered\":{" + "                                      \"query\":{" + "                                          \"span_near\": {" + "                                              \"clauses\":" + clauses + "," + "                                              \"slop\":" + slop.toString() + "," + "                                              \"in_order\":" + in_order.toString() + "," + "                                              \"collect_payloads\": false}}," + "                                      \"filter\":{\"ids\":{\"values\":[\"" + docId + "\"]}}}}," + "                              \"highlight\":{\"fields\":{\"" + field + "\":{}}}," + "                              \"size\":1}";
    System.out.println(body);
    conn.setRequestProperty("Content-Length", Integer.toString(body.length()));
    conn.getOutputStream().write(body.getBytes("UTF-8"));
    final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    final StringBuilder result = new StringBuilder();
    for (String line = null; (line = reader.readLine()) != null; ) {
        result.append(line);
    }
    final JsonFactory factory = new JsonFactory();
    final ObjectMapper mapper = new ObjectMapper(factory);
    final Map<String, Object> hits = mapper.readValue(result.toString(), new TypeReference<Map<String, Object>>() {
    });
    final List<Integer> positions = new ArrayList<>();
    if (hits.get("hits") != null && ((Map<String, Object>) hits.get("hits")).containsKey("hits")) {
        for (String hlField : ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0)).get("highlight")).keySet()) {
            final String text = (String) ((Map<String, Object>) (((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0).get("_source"))).get(hlField);
            final List<String> highlights = (List<String>) ((Map<String, Object>) (((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0).get("highlight"))).get(hlField);
            for (String HL : highlights) {
                String cleanHL = HL.replaceAll("<em>", "");
                cleanHL = cleanHL.replaceAll("</em>", "");
                int baseindex = text.indexOf(cleanHL);
                // in case the highlight not found in body
                if (baseindex == -1) {
                    continue;
                }
                while (HL.indexOf("<em>") != -1) {
                    int start = HL.indexOf("<em>") + baseindex;
                    HL = HL.replace("<em>", "");
                    int end = HL.indexOf("</em>") + baseindex;
                    HL = HL.replace("</em>", "");
                    positions.add(start);
                    positions.add(end);
                }
            }
        }
    }
    return positions;
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ArrayList(java.util.ArrayList) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)266 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)102 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)91 JsonParser (com.fasterxml.jackson.core.JsonParser)78 Test (org.junit.Test)65 IOException (java.io.IOException)62 StringWriter (java.io.StringWriter)60 Map (java.util.Map)27 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 List (java.util.List)18 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)16 JsonToken (com.fasterxml.jackson.core.JsonToken)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 File (java.io.File)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 InputStreamReader (java.io.InputStreamReader)9 TypeReference (com.fasterxml.jackson.core.type.TypeReference)8 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8