Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeEndObject()

The following examples show how to use com.fasterxml.jackson.core.JsonGenerator#writeEndObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bean01EntityBindMap.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public int serializeOnJacksonAsString(Bean01Entity object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field id (mapped with "id")
  if (object.getId()!=null)  {
    jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(object.getId()));
  }

  // field text (mapped with "text")
  if (object.getText()!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("text", object.getText());
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 2
Source File: ConversationStateIOProvider.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void writeObject(Attribute attribute, int elementId, JsonGenerator jsonGenerator, GraphReadMethods graph, GraphByteWriter byteWriter, boolean verbose) throws IOException {
    if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) {
        final ConversationState state = (ConversationState) graph.getObjectValue(attribute.getId(), elementId);
        if (state == null) {
            jsonGenerator.writeNullField(attribute.getName());
        } else {
            jsonGenerator.writeObjectFieldStart(attribute.getName());

            jsonGenerator.writeArrayFieldStart(HIDDEN_CONTRIBUTION_PROVIDERS_TAG);
            for (String hiddenContributionProvider : state.getHiddenContributionProviders()) {
                jsonGenerator.writeString(hiddenContributionProvider);
            }
            jsonGenerator.writeEndArray();

            jsonGenerator.writeArrayFieldStart(SENDER_ATTRIBUTES_TAG);
            for (String senderAttribute : state.getSenderAttributes()) {
                jsonGenerator.writeString(senderAttribute);
            }
            jsonGenerator.writeEndArray();

            jsonGenerator.writeEndObject();
        }
    }
}
 
Example 3
Source File: Bean2BindMap.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public int serializeOnJackson(Bean2 object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field name (mapped with "name")
  if (object.name!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("name", object.name);
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 4
Source File: ConsequenceQuery.java    From algoliasearch-client-java-2 with MIT License 5 votes vote down vote up
@Override
public void serialize(ConsequenceQuery value, JsonGenerator gen, SerializerProvider serializers)
    throws IOException {
  /*
   * Consequence query edits will override regular "query" - both can't be set at the same time
   * https://www.algolia.com/doc/api-reference/api-methods/save-rule/#method-param-query
   * */
  if (!AlgoliaUtils.isNullOrEmptyWhiteSpace(value.getQueryString())) {
    gen.writeString(value.getQueryString());
  } else {
    gen.writeStartObject();
    gen.writeObjectField("edits", value.getEdits());
    gen.writeEndObject();
  }
}
 
Example 5
Source File: Bean64Table.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueStrinList serialization
 */
public static byte[] serializeValueStrinList(LinkedList<String> value) {
  if (value==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) {
    JsonGenerator jacksonSerializer=wrapper.jacksonGenerator;
    jacksonSerializer.writeStartObject();
    int fieldCount=0;
    if (value!=null)  {
      fieldCount++;
      int n=value.size();
      String item;
      // write wrapper tag
      jacksonSerializer.writeFieldName("element");
      jacksonSerializer.writeStartArray();
      for (int i=0; i<n; i++) {
        item=value.get(i);
        if (item==null) {
          jacksonSerializer.writeNull();
        } else {
          jacksonSerializer.writeString(item);
        }
      }
      jacksonSerializer.writeEndArray();
    }
    jacksonSerializer.writeEndObject();
    jacksonSerializer.flush();
    return stream.toByteArray();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 6
Source File: BeanDaoImpl.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for param serializer1 serialization
 */
private byte[] serializer1(BeanInner[] value) {
  if (value==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) {
    JsonGenerator jacksonSerializer=wrapper.jacksonGenerator;
    int fieldCount=0;
    jacksonSerializer.writeStartObject();
    if (value!=null)  {
      int n=value.length;
      BeanInner item;
      // write wrapper tag
      jacksonSerializer.writeFieldName("element");
      jacksonSerializer.writeStartArray();
      for (int i=0; i<n; i++) {
        item=value[i];
        if (item==null) {
          jacksonSerializer.writeNull();
        } else {
          beanInnerBindMap.serializeOnJackson(item, jacksonSerializer);
        }
      }
      jacksonSerializer.writeEndArray();
    }
    jacksonSerializer.writeEndObject();
    jacksonSerializer.flush();
    return stream.toByteArray();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 7
Source File: StringBeanTable.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute value serialization
 */
public static byte[] serializeValue(String[] value) {
  if (value==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) {
    JsonGenerator jacksonSerializer=wrapper.jacksonGenerator;
    jacksonSerializer.writeStartObject();
    int fieldCount=0;
    if (value!=null)  {
      fieldCount++;
      int n=value.length;
      String item;
      // write wrapper tag
      jacksonSerializer.writeFieldName("element");
      jacksonSerializer.writeStartArray();
      for (int i=0; i<n; i++) {
        item=value[i];
        if (item==null) {
          jacksonSerializer.writeNull();
        } else {
          jacksonSerializer.writeString(item);
        }
      }
      jacksonSerializer.writeEndArray();
    }
    jacksonSerializer.writeEndObject();
    jacksonSerializer.flush();
    return stream.toByteArray();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 8
Source File: ThumbnailBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public int serializeOnJackson(Thumbnail object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field height (mapped with "height")
  if (object.height!=null)  {
    fieldCount++;
    jacksonSerializer.writeNumberField("height", object.height);
  }

  // field url (mapped with "url")
  if (object.url!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("url", UrlUtils.write(object.url));
  }

  // field width (mapped with "width")
  if (object.width!=null)  {
    fieldCount++;
    jacksonSerializer.writeNumberField("width", object.width);
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 9
Source File: QueryBuilders.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override void writeJson(final JsonGenerator generator) throws IOException {
  generator.writeStartObject();
  generator.writeFieldName("match");
  generator.writeStartObject();
  generator.writeFieldName(fieldName);
  generator.writeStartArray();
  for (Object value: values) {
    writeObject(generator, value);
  }
  generator.writeEndArray();
  generator.writeEndObject();
  generator.writeEndObject();
}
 
Example 10
Source File: TraceCommonService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private static void writeThreadStats(Trace.ThreadStats threadStats, JsonGenerator jg)
        throws IOException {
    jg.writeStartObject();
    jg.writeNumberField("totalCpuNanos", threadStats.getCpuNanos());
    jg.writeNumberField("totalBlockedNanos", threadStats.getBlockedNanos());
    jg.writeNumberField("totalWaitedNanos", threadStats.getWaitedNanos());
    jg.writeNumberField("totalAllocatedBytes", threadStats.getAllocatedBytes());
    jg.writeEndObject();
}
 
Example 11
Source File: MetricsElasticsearchModule.java    From oneops with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(BulkIndexOperationHeader bulkIndexOperationHeader, JsonGenerator json, SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeObjectFieldStart("index");
    if (bulkIndexOperationHeader.index != null) {
        json.writeStringField("_index", bulkIndexOperationHeader.index);
    }
    if (bulkIndexOperationHeader.type != null) {
        json.writeStringField("_type", bulkIndexOperationHeader.type);
    }
    json.writeEndObject();
    json.writeEndObject();
}
 
Example 12
Source File: ContingencySerializer.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void serialize(Contingency contingency, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeStringField("id", contingency.getId());
    jsonGenerator.writeObjectField("elements", contingency.getElements());

    JsonUtil.writeExtensions(contingency, jsonGenerator, serializerProvider);

    jsonGenerator.writeEndObject();
}
 
Example 13
Source File: JsonFormatter.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void generateCompound(JsonGenerator generator, CompoundExplainer explainer) throws IOException {
    generator.writeStartObject();
    generator.writeObjectField("type", explainer.getType().name().toLowerCase());
    for (Map.Entry<Label, List<Explainer>> entry : explainer.get().entrySet()) {
        generator.writeFieldName(entry.getKey().name().toLowerCase());
        generator.writeStartArray();
        for (Explainer child : entry.getValue()) {
            generate(generator, child);
        }
        generator.writeEndArray();
    }
    generator.writeEndObject();
}
 
Example 14
Source File: ImageBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public int serializeOnJackson(Image object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field height (mapped with "height")
  fieldCount++;
  jacksonSerializer.writeNumberField("height", object.height);

  // field link (mapped with "link")
  if (object.link!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("link", object.link);
  }

  // field title (mapped with "title")
  if (object.title!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("title", object.title);
  }

  // field url (mapped with "url")
  if (object.url!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("url", object.url);
  }

  // field width (mapped with "width")
  fieldCount++;
  jacksonSerializer.writeNumberField("width", object.width);

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 15
Source File: GeometrySerializer.java    From jackson-datatype-jts with Apache License 2.0 5 votes vote down vote up
private void writePolygon(JsonGenerator jgen, Polygon value)
		throws IOException {
	jgen.writeStartObject();
	jgen.writeStringField(TYPE, POLYGON);
	jgen.writeFieldName(COORDINATES);
	writePolygonCoordinates(jgen, value);

	jgen.writeEndObject();
}
 
Example 16
Source File: HttpApiV2AuthorizerMap.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(HttpApiV2AuthorizerMap httpApiV2AuthorizerMap, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();
    if (httpApiV2AuthorizerMap.isJwt()) {
        jsonGenerator.writeObjectField(JWT_KEY, httpApiV2AuthorizerMap.getJwtAuthorizer());
    }
    jsonGenerator.writeEndObject();
}
 
Example 17
Source File: OpenRtbJsonWriter.java    From openrtb with Apache License 2.0 4 votes vote down vote up
public final void writeSource(Source source, JsonGenerator gen) throws IOException {
  gen.writeStartObject();
  writeSourceFields(source, gen);
  writeExtensions(source, gen);
  gen.writeEndObject();
}
 
Example 18
Source File: JsonPropertyWriter.java    From odata with Apache License 2.0 4 votes vote down vote up
@Override
protected ChunkedActionRenderResult getComplexPropertyChunked(
        Object data, StructuredType type, ChunkedStreamAction action, ChunkedActionRenderResult previousResult)
        throws ODataException {
    try {
        JsonGenerator generator = previousResult.getWriter() == null ?
                JSON_FACTORY.createGenerator(previousResult.getOutputStream(),
                        JsonEncoding.UTF8).setCodec(new JsonCodecMapper()) :
                (JsonGenerator) previousResult.getWriter();
        switch (action) {
            case START_DOCUMENT:
                generator.writeStringField(CONTEXT, getContextURL(getODataUri(), getEntityDataModel()));
                generator.writeFieldName("value");
                if (isCollection(data)) {
                    generator.writeStartArray();
                }

                return new ChunkedActionRenderResult(previousResult.getOutputStream(), generator);
            case BODY_DOCUMENT:
                if (isCollection(data)) {
                    for (Object obj : (List) data) {
                        writeAllProperties(obj, type);
                    }
                } else {
                    writeAllProperties(data, type);
                }

                return new ChunkedActionRenderResult(previousResult.getOutputStream(), generator);
            case END_DOCUMENT:
                if (isCollection(data)) {
                    generator.writeEndArray();
                }
                generator.writeEndObject();

                return new ChunkedActionRenderResult(previousResult.getOutputStream(), generator);
            default:
                throw new ODataRenderException(format(
                        "Unable to render complex type value because of wrong ChunkedStreamAction: {0}",
                        action));
        }
    } catch (ODataException | IOException e) {
        throw new ODataRenderException("Unable to marshall complex");
    }
}
 
Example 19
Source File: OpenRtbJsonWriter.java    From openrtb with Apache License 2.0 4 votes vote down vote up
public final void writeProducer(Producer producer, JsonGenerator gen) throws IOException {
  gen.writeStartObject();
  writeProducerFields(producer, gen);
  writeExtensions(producer, gen);
  gen.writeEndObject();
}
 
Example 20
Source File: FolderSerializerWithDefaultSerializerStored.java    From tutorials with MIT License 3 votes vote down vote up
@Override
public void serialize(Folder value, JsonGenerator gen, SerializerProvider provider) throws IOException {

    gen.writeStartObject();
    gen.writeStringField("name", value.getName());

    provider.defaultSerializeField("files", value.getFiles(), gen);

    gen.writeFieldName("details");
    defaultSerializer.serialize(value, gen, provider);

    gen.writeEndObject();

}