Example usage for com.fasterxml.jackson.core JsonGenerator writeBooleanField

List of usage examples for com.fasterxml.jackson.core JsonGenerator writeBooleanField

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator writeBooleanField.

Prototype

public final void writeBooleanField(String fieldName, boolean value)
        throws IOException, JsonGenerationException 

Source Link

Document

Convenience method for outputting a field entry ("member") that has a boolean value.

Usage

From source file:tds.student.web.controls.dummy.GlobalJavascriptWriter.java

public void writeCustomSettings() throws IOException {
    StringWriter sw = new StringWriter();
    JsonFactory jsonFactory = new JsonFactory();
    JsonGenerator jsonWriter = jsonFactory.createGenerator(sw);

    jsonWriter.writeStartObject();/*from  w  w w. ja  va 2  s . c  om*/

    // TODO Shajib:
    // jsonWriter.writeBooleanField ("showExceptions",
    // DebugSettings.showClientExceptions());
    jsonWriter.writeBooleanField("ignoreForbiddenApps", DebugSettings.ignoreForbiddenApps());
    jsonWriter.writeBooleanField("ignoreBrowserChecks", DebugSettings.ignoreBrowserChecks());
    jsonWriter.writeEndObject();
    jsonWriter.close();
    _writer.write(String.format("TDS.Debug = %s; ", sw.toString()));
    _writer.write("\n\r");
}

From source file:com.ntsync.shared.RawContact.java

private static void writeImList(JsonGenerator g, List<RawImData> list) throws IOException {
    if (list != null) {
        g.writeArrayFieldStart(ContactConstants.IM);
        for (RawImData listItem : list) {
            g.writeStartObject();// w w  w  . j  a  va2s.c o  m
            writeField(g, ContactConstants.DATA, listItem.getData());
            g.writeStringField(ContactConstants.TYPE, String.valueOf(listItem.getType().getVal()));
            writeField(g, ContactConstants.LABEL, listItem.getLabel());
            g.writeStringField(ContactConstants.PROTOCOL_TYPE, String.valueOf(listItem.getProtType().getVal()));
            writeField(g, ContactConstants.PROTOCOL_CUSTOM_PROT, listItem.getCustomProtocolName());
            if (listItem.isSuperPrimary()) {
                g.writeBooleanField(ContactConstants.SUPERPRIMARY, true);
            }
            if (listItem.isPrimary()) {
                g.writeBooleanField(ContactConstants.PRIMARY, true);
            }
            g.writeEndObject();
        }
        g.writeEndArray();
    }
}

From source file:com.neoteric.starter.metrics.report.elastic.ElasticsearchReporter.java

private void checkForIndexTemplate() {
    try {//from   w ww  .  j a v a 2s .  c o  m
        HttpURLConnection connection = openConnection("/_template/metrics_template", "HEAD");
        connection.disconnect();
        boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND;

        // nothing there, lets create it
        if (isTemplateMissing) {
            LOGGER.debug("No metrics template found in elasticsearch. Adding...");
            HttpURLConnection putTemplateConnection = openConnection("/_template/metrics_template", "PUT");
            JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream());
            json.writeStartObject();
            json.writeStringField("template", index + "*");
            json.writeObjectFieldStart("mappings");

            json.writeObjectFieldStart("_default_");
            json.writeObjectFieldStart("_all");
            json.writeBooleanField("enabled", false);
            json.writeEndObject();
            json.writeObjectFieldStart("properties");
            json.writeObjectFieldStart("name");
            json.writeObjectField("type", "string");
            json.writeObjectField("index", "not_analyzed");
            json.writeEndObject();
            json.writeEndObject();
            json.writeEndObject();

            json.writeEndObject();
            json.writeEndObject();
            json.flush();

            putTemplateConnection.disconnect();
            if (putTemplateConnection.getResponseCode() != HttpStatus.OK.value()) {
                LOGGER.error(
                        "Error adding metrics template to elasticsearch: {}/{}"
                                + putTemplateConnection.getResponseCode(),
                        putTemplateConnection.getResponseMessage());
            }
        }
        checkedForIndexTemplate = true;
    } catch (IOException e) {
        LOGGER.error("Error when checking/adding metrics template to elasticsearch", e);
    }
}

From source file:org.apache.olingo.client.core.serialization.JsonPropertySerializer.java

protected void doContainerSerialize(final ResWrap<Property> container, final JsonGenerator jgen)
        throws IOException, EdmPrimitiveTypeException {

    final Property property = container.getPayload();

    jgen.writeStartObject();/* w ww  .  j  av  a2  s  .  c  om*/

    if (serverMode && container.getContextURL() != null) {
        jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString());
    }

    if (StringUtils.isNotBlank(property.getType())) {
        jgen.writeStringField(Constants.JSON_TYPE,
                new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build().external());
    }

    for (Annotation annotation : property.getAnnotations()) {
        valuable(jgen, annotation, "@" + annotation.getTerm());
    }

    if (property.isNull()) {
        jgen.writeBooleanField(Constants.JSON_NULL, true);
    } else if (property.isGeospatial() || property.isCollection()) {
        valuable(jgen, property, Constants.VALUE);
    } else if (property.isPrimitive()) {
        final EdmTypeInfo typeInfo = property.getType() == null ? null
                : new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build();

        jgen.writeFieldName(Constants.VALUE);
        primitiveValue(jgen, typeInfo, property.asPrimitive());
    } else if (property.isEnum()) {
        jgen.writeStringField(Constants.VALUE, property.asEnum().toString());
    } else if (property.isComplex()) {
        for (Property cproperty : property.asComplex().getValue()) {
            valuable(jgen, cproperty, cproperty.getName());
        }
    } else if (property.isComplex()) {
        for (Property cproperty : property.asComplex().getValue()) {
            valuable(jgen, cproperty, cproperty.getName());
        }
    }

    jgen.writeEndObject();
}

From source file:org.canova.api.conf.Configuration.java

/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}//from   w ww .j a  v a2s. c om
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration conf, Writer out) throws IOException {
    Configuration config = new Configuration(conf, true);
    config.reloadConfiguration();
    JsonFactory dumpFactory = new JsonFactory();
    JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
    dumpGenerator.writeStartObject();
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    dumpGenerator.flush();
    for (Map.Entry<Object, Object> item : config.getProps().entrySet()) {
        dumpGenerator.writeStartObject();
        dumpGenerator.writeStringField("key", (String) item.getKey());
        dumpGenerator.writeStringField("value", config.get((String) item.getKey()));
        dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey()));
        dumpGenerator.writeStringField("resource", config.updatingResource.get(item.getKey()));
        dumpGenerator.writeEndObject();
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
    dumpGenerator.flush();
}

From source file:io.swagger.inflector.processors.JsonNodeExampleSerializer.java

public void writeValue(JsonGenerator jgen, String field, Example o) throws IOException {
    if (o instanceof ArrayExample) {
        ArrayExample obj = (ArrayExample) o;
        jgen.writeArrayFieldStart(field);
        for (Example item : obj.getItems()) {
            if (item.getName() != null) {
                jgen.writeStartObject();
                writeTo(jgen, item);/*from ww  w.  jav a 2s  .co  m*/
                jgen.writeEndObject();
            } else {
                writeTo(jgen, item);
            }
        }
        jgen.writeEndArray();
    } else if (o instanceof BooleanExample) {
        BooleanExample obj = (BooleanExample) o;
        if (field != null) {
            jgen.writeBooleanField(field, obj.getValue());
        } else {
            jgen.writeBoolean(obj.getValue());
        }
    } else if (o instanceof DecimalExample) {
        DecimalExample obj = (DecimalExample) o;
        if (field != null) {
            jgen.writeNumberField(field, obj.getValue());
        } else {
            jgen.writeNumber(obj.getValue());
        }
    } else if (o instanceof DoubleExample) {
        DoubleExample obj = (DoubleExample) o;
        if (field != null) {
            jgen.writeNumberField(field, obj.getValue());
        } else {
            jgen.writeNumber(obj.getValue());
        }
    } else if (o instanceof FloatExample) {
        FloatExample obj = (FloatExample) o;
        if (field != null) {
            jgen.writeNumberField(field, obj.getValue());
        } else {
            jgen.writeNumber(obj.getValue());
        }
    } else if (o instanceof IntegerExample) {
        IntegerExample obj = (IntegerExample) o;
        if (field != null) {
            jgen.writeNumberField(field, obj.getValue());
        } else {
            jgen.writeNumber(obj.getValue());
        }
    } else if (o instanceof LongExample) {
        LongExample obj = (LongExample) o;
        if (field != null) {
            jgen.writeNumberField(field, obj.getValue());
        } else {
            jgen.writeNumber(obj.getValue());
        }
    } else if (o instanceof ObjectExample) {
        ObjectExample obj = (ObjectExample) o;
        if (field != null) {
            jgen.writeObjectField(field, obj);
        }
    } else if (o instanceof StringExample) {
        StringExample obj = (StringExample) o;
        if (field != null) {
            jgen.writeStringField(field, obj.getValue());
        } else {
            jgen.writeString(obj.getValue());
        }
    }
}

From source file:de.escalon.hypermedia.spring.de.escalon.hypermedia.spring.jackson.LinkListSerializer.java

private void writeHydraVariableMapping(JsonGenerator jgen, @Nullable ActionDescriptor actionDescriptor,
        Collection<String> variableNames) throws IOException {
    for (String requestParamName : variableNames) {
        jgen.writeStartObject();/*from  w w  w.j  a  v a  2 s .  c o m*/
        jgen.writeStringField("@type", "hydra:IriTemplateMapping");
        jgen.writeStringField("hydra:variable", requestParamName);
        if (actionDescriptor != null) {
            jgen.writeBooleanField("hydra:required",
                    actionDescriptor.getActionInputParameter(requestParamName).isRequired());
            jgen.writeStringField("hydra:property",
                    getExposedPropertyOrParamName(actionDescriptor.getActionInputParameter(requestParamName)));
        }
        jgen.writeEndObject();
    }
}

From source file:org.elasticsearch.metrics.ElasticsearchReporter.java

/**
 * This index template is automatically applied to all indices which start with the index name
 * The index template simply configures the name not to be analyzed
 *//*  w  w w.j a  va 2  s.co m*/
private void checkForIndexTemplate() {
    try {
        HttpURLConnection connection = openConnection("/_template/metrics_template", "HEAD");
        if (connection == null) {
            LOGGER.error("Could not connect to any configured elasticsearch instances: {}",
                    Arrays.asList(hosts));
            return;
        }
        connection.disconnect();

        boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND;

        // nothing there, lets create it
        if (isTemplateMissing) {
            LOGGER.debug("No metrics template found in elasticsearch. Adding...");
            HttpURLConnection putTemplateConnection = openConnection("/_template/metrics_template", "PUT");
            if (putTemplateConnection == null) {
                LOGGER.error("Error adding metrics template to elasticsearch");
                return;
            }

            JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream());
            json.writeStartObject();
            json.writeStringField("template", index + "*");
            json.writeObjectFieldStart("mappings");

            json.writeObjectFieldStart("_default_");
            json.writeObjectFieldStart("_all");
            json.writeBooleanField("enabled", false);
            json.writeEndObject();
            json.writeObjectFieldStart("properties");
            json.writeObjectFieldStart("name");
            json.writeObjectField("type", "string");
            json.writeObjectField("index", "not_analyzed");
            json.writeEndObject();
            json.writeEndObject();
            json.writeEndObject();

            json.writeEndObject();
            json.writeEndObject();
            json.flush();

            putTemplateConnection.disconnect();
            if (putTemplateConnection.getResponseCode() != 200) {
                LOGGER.error(
                        "Error adding metrics template to elasticsearch: {}/{}"
                                + putTemplateConnection.getResponseCode(),
                        putTemplateConnection.getResponseMessage());
            }
        }
        checkedForIndexTemplate = true;
    } catch (IOException e) {
        LOGGER.error("Error when checking/adding metrics template to elasticsearch", e);
    }
}

From source file:com.oneops.metrics.es.ElasticsearchReporter.java

/**
 * This index template is automatically applied to all indices which start with the index name
 * The index template simply configures the name not to be analyzed
 *///from  w  w w  .jav a  2  s .c om
private void checkForIndexTemplate() {
    try {
        HttpURLConnection connection = openConnection("/_template/metrics_template", "HEAD");
        if (connection == null) {
            LOGGER.error("Could not connect to any configured elasticsearch instances: {}",
                    Arrays.asList(hosts));
            return;
        }
        connection.disconnect();

        boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND;

        // nothing there, lets create it
        if (isTemplateMissing) {
            LOGGER.debug("No metrics template found in elasticsearch. Adding...");
            HttpURLConnection putTemplateConnection = openConnection("/_template/metrics_template", "PUT");
            JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream());
            json.writeStartObject();
            json.writeStringField("template", index + "*");
            json.writeObjectFieldStart("mappings");

            json.writeObjectFieldStart("_default_");
            json.writeObjectFieldStart("_all");
            json.writeBooleanField("enabled", false);
            json.writeEndObject();
            json.writeObjectFieldStart("properties");
            json.writeObjectFieldStart("name");
            json.writeObjectField("type", "string");
            json.writeObjectField("index", "not_analyzed");
            json.writeEndObject();
            json.writeEndObject();
            json.writeEndObject();

            json.writeEndObject();
            json.writeEndObject();
            json.flush();

            putTemplateConnection.disconnect();
            if (putTemplateConnection.getResponseCode() != 200) {
                LOGGER.error(
                        "Error adding metrics template to elasticsearch: {}/{}"
                                + putTemplateConnection.getResponseCode(),
                        putTemplateConnection.getResponseMessage());
            }
        }
        checkedForIndexTemplate = true;
    } catch (IOException e) {
        LOGGER.error("Error when checking/adding metrics template to elasticsearch", e);
    }
}

From source file:com.predic8.membrane.core.interceptor.administration.AdminRESTInterceptor.java

@Mapping("/admin/rest/proxies(/?\\?.*)?")
public Response getProxies(final QueryParameter params, String relativeRootPath) throws Exception {
    final List<AbstractServiceProxy> proxies = getServiceProxies();

    if ("order".equals(params.getString("sort"))) {
        if (params.getString("order", "asc").equals("desc"))
            Collections.reverse(proxies);
    } else {/*  w w  w  . ja  v a 2  s .co  m*/
        Collections.sort(proxies, ComparatorFactory.getAbstractServiceProxyComparator(
                params.getString("sort", "name"), params.getString("order", "asc")));
    }

    final int offset = params.getInt("offset", 0);
    int max = params.getInt("max", proxies.size());

    final List<AbstractServiceProxy> paginated = proxies.subList(offset,
            Math.min(offset + max, proxies.size()));

    return json(new JSONContent() {
        public void write(JsonGenerator gen) throws Exception {
            gen.writeStartObject();
            gen.writeArrayFieldStart("proxies");
            int i = offset;
            if (params.getString("order", "asc").equals("desc"))
                i = proxies.size() - i + 1;
            for (AbstractServiceProxy p : paginated) {
                gen.writeStartObject();
                gen.writeNumberField("order", i += params.getString("order", "asc").equals("desc") ? -1 : 1);
                gen.writeStringField("name", p.toString());
                gen.writeBooleanField("active", p.isActive());
                if (!p.isActive())
                    gen.writeStringField("error", p.getErrorState());
                gen.writeNumberField("listenPort", p.getKey().getPort());
                gen.writeStringField("virtualHost", p.getKey().getHost());
                gen.writeStringField("method", p.getKey().getMethod());
                gen.writeStringField("path", p.getKey().getPath());
                gen.writeStringField("targetHost", p.getTargetHost());
                gen.writeNumberField("targetPort", p.getTargetPort());
                gen.writeNumberField("count", p.getCount());
                gen.writeObjectFieldStart("actions");
                if (!isReadOnly()) {
                    gen.writeStringField("delete", "/admin/service-proxy/delete?name="
                            + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
                }
                if (!p.isActive())
                    gen.writeStringField("start", "/admin/service-proxy/start?name="
                            + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
                gen.writeEndObject();
                gen.writeEndObject();
            }
            gen.writeEndArray();
            gen.writeNumberField("total", proxies.size());
            gen.writeEndObject();
        }
    });
}