Search in sources :

Example 46 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project Hystrix by Netflix.

the class HystrixConfigurationJsonStream method convertToString.

public static String convertToString(HystrixConfiguration config) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createGenerator(jsonString);
    json.writeStartObject();
    json.writeStringField("type", "HystrixConfig");
    json.writeObjectFieldStart("commands");
    for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig().entrySet()) {
        final HystrixCommandKey key = entry.getKey();
        final HystrixCommandConfiguration commandConfig = entry.getValue();
        writeCommandConfigJson(json, key, commandConfig);
    }
    json.writeEndObject();
    json.writeObjectFieldStart("threadpools");
    for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> entry : config.getThreadPoolConfig().entrySet()) {
        final HystrixThreadPoolKey threadPoolKey = entry.getKey();
        final HystrixThreadPoolConfiguration threadPoolConfig = entry.getValue();
        writeThreadPoolConfigJson(json, threadPoolKey, threadPoolConfig);
    }
    json.writeEndObject();
    json.writeObjectFieldStart("collapsers");
    for (Map.Entry<HystrixCollapserKey, HystrixCollapserConfiguration> entry : config.getCollapserConfig().entrySet()) {
        final HystrixCollapserKey collapserKey = entry.getKey();
        final HystrixCollapserConfiguration collapserConfig = entry.getValue();
        writeCollapserConfigJson(json, collapserKey, collapserConfig);
    }
    json.writeEndObject();
    json.writeEndObject();
    json.close();
    return jsonString.getBuffer().toString();
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) StringWriter(java.io.StringWriter) HystrixCommandConfiguration(com.netflix.hystrix.config.HystrixCommandConfiguration) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) Map(java.util.Map) HystrixCollapserConfiguration(com.netflix.hystrix.config.HystrixCollapserConfiguration) HystrixThreadPoolConfiguration(com.netflix.hystrix.config.HystrixThreadPoolConfiguration)

Example 47 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project Hystrix by Netflix.

the class SerialHystrixConfiguration method toJsonString.

public static String toJsonString(HystrixConfiguration config) {
    StringWriter jsonString = new StringWriter();
    try {
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        serializeConfiguration(config, json);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return jsonString.getBuffer().toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 48 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project Hystrix by Netflix.

the class SerialHystrixDashboardData method toJsonString.

public static String toJsonString(HystrixCollapserMetrics collapserMetrics) {
    StringWriter jsonString = new StringWriter();
    try {
        JsonGenerator json = jsonFactory.createGenerator(jsonString);
        writeCollapserMetrics(collapserMetrics, json);
        json.close();
        return jsonString.getBuffer().toString();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 49 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project wiquery by WiQuery.

the class AutocompleteComponent method onBeforeRenderAutocomplete.

@Override
protected void onBeforeRenderAutocomplete(Autocomplete<?> autocomplete) {
    StringWriter sw = new StringWriter();
    try {
        JsonGenerator gen = new JsonFactory().createGenerator(sw);
        List<Object> json = new ArrayList<Object>();
        T defaultValue = AutocompleteComponent.this.getModelObject();
        AutocompleteJson value = null;
        Integer index = 0;
        for (T obj : AutocompleteComponent.this.list.getObject()) {
            index++;
            value = newAutocompleteJson(index, obj);
            json.add(value);
            if (obj.equals(defaultValue)) {
                autocomplete.setDefaultModelObject(value.getLabel());
                getAutocompleteHidden().setModelObject(value.getValueId());
            }
        }
        new ObjectMapper().writeValue(gen, json);
    } catch (IOException e) {
        throw new WicketRuntimeException(e);
    }
    autocomplete.getOptions().put("source", sw.toString());
}
Also used : StringWriter(java.io.StringWriter) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ArrayList(java.util.ArrayList) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 50 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project pinpoint by naver.

the class MappingJackson2JsonpView method renderMergedOutputModel.

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Object value = filterModel(model);
    JsonGenerator generator = this.objectMapper.getFactory().createGenerator(response.getOutputStream(), this.encoding);
    if (this.prefixJson) {
        generator.writeRaw("{} && ");
    }
    final String callBackParameter = getCallBackParameter(request);
    if (StringUtils.isEmpty(callBackParameter)) {
        this.objectMapper.writeValue(generator, value);
    } else {
        generator.writeRaw(callBackParameter);
        generator.writeRaw(cbPrefix);
        this.objectMapper.writeValue(generator, value);
        generator.writeRaw(cbSuffix);
        generator.writeRaw(cbEnd);
    }
    generator.flush();
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)187 StringWriter (java.io.StringWriter)81 IOException (java.io.IOException)52 JsonFactory (com.fasterxml.jackson.core.JsonFactory)44 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 Map (java.util.Map)17 OutputStream (java.io.OutputStream)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 JsonParser (com.fasterxml.jackson.core.JsonParser)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 File (java.io.File)7 OutputStreamWriter (java.io.OutputStreamWriter)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)6 List (java.util.List)5 AccessExecutionVertex (org.apache.flink.runtime.executiongraph.AccessExecutionVertex)5 JsonEncoding (com.fasterxml.jackson.core.JsonEncoding)4