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

The following examples show how to use com.fasterxml.jackson.core.JsonGenerator#writeString() . 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: IdSerializer.java    From EDDI with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(String t, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    if (!(jsonGenerator instanceof BsonGenerator)) {
        jsonGenerator.writeString(t);
        return;
    }
    serialize(t, (BsonGenerator) jsonGenerator, serializerProvider);
}
 
Example 2
Source File: MutationSerializer.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void serialize(Mutation condition, JsonGenerator generator,
    SerializerProvider provider) throws IOException {
    generator.writeStartArray();
    generator.writeString(condition.getColumn());
    generator.writeString(condition.getMutator().toString());
    generator.writeObject(condition.getValue());
    generator.writeEndArray();
}
 
Example 3
Source File: ProfileAttributesEnumSerializer.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void serialize(ProfileAttributesValueTypes profileAttribute, JsonGenerator generator, SerializerProvider provider)
		throws IOException, JsonProcessingException {
	generator.writeStartObject();
	generator.writeFieldName("name");
	generator.writeString(profileAttribute.name());
	generator.writeFieldName("type");
	generator.writeString(profileAttribute.getType());
	generator.writeEndObject();
}
 
Example 4
Source File: XssStringJsonSerializer.java    From runscore with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
		throws IOException {
	if (value != null) {
		String encodedValue = EscapeUtil.escapeHtml4(value);
		jsonGenerator.writeString(encodedValue);
	}
}
 
Example 5
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute stringList serialization
 */
protected String serializeStringList(List<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("stringList");
      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.toString();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 6
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute stringArray serialization
 */
protected String serializeStringArray(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("stringArray");
      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.toString();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 7
Source File: BindRightPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute stringArray serialization
 */
protected String serializeStringArray(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("stringArray");
      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.toString();
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 8
Source File: Format.java    From smartsheet-java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Format format, JsonGenerator generator, SerializerProvider provider) throws IOException {
    StringBuilder stringBuilder = new StringBuilder(30);
    String separator = "";
    for (int formatValue : format.formatArray) {
        stringBuilder.append(separator);
        separator = ",";

        if (formatValue != UNSET) {
            stringBuilder.append(formatValue);
        }
    }

    generator.writeString(stringBuilder.toString());
}
 
Example 9
Source File: JsonDateSerializer.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Date date, JsonGenerator generator, SerializerProvider provider) throws IOException,
		JsonProcessingException {
	synchronized (dateFormat) {
		String formatted = dateFormat.format(date);
		generator.writeString(formatted);
	}
}
 
Example 10
Source File: PipelineOptionsFactoryTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
    JacksonIncompatible jacksonIncompatible,
    JsonGenerator jsonGenerator,
    SerializerProvider serializerProvider)
    throws IOException, JsonProcessingException {
  jsonGenerator.writeString(jacksonIncompatible.value);
}
 
Example 11
Source File: DateTimeSerde.java    From act with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider serializers)
    throws IOException, JsonProcessingException {
  gen.writeString(DATE_TIME_FORMATTER.print(value));
}
 
Example 12
Source File: JoynrEnumSerializer.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
                                                                                   JsonGenerationException {
    jgen.writeString(value.name());

}
 
Example 13
Source File: LocalDateSerializer.java    From Pixiv-Illustration-Collection-Backend with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider sp) throws IOException {
    gen.writeString(value.format(DateTimeFormatter.ISO_LOCAL_DATE));
}
 
Example 14
Source File: MoneyModule.java    From cqrs-hotel with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Money value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeString(value.toString());
}
 
Example 15
Source File: DateSerializer.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
@Override public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
  DateTime dateTime = new DateTime(value.getTime());
  gen.writeString(dateTime.toString());
}
 
Example 16
Source File: ChannelBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public int serializeOnJacksonAsString(Channel object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

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

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

  // field id (mapped with "id")
  jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(object.id));

  // field image (mapped with "image")
  if (object.image!=null)  {
    fieldCount++;
    jacksonSerializer.writeFieldName("image");
    if (imageBindMap.serializeOnJacksonAsString(object.image, jacksonSerializer)==0) {
      jacksonSerializer.writeNullField("image");
    }
  }

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

  // field lastBuildDate (mapped with "lastBuildDate")
  if (object.lastBuildDate!=null)  {
    fieldCount++;
    // using type adapter bind.rss.DateAdapter
    jacksonSerializer.writeStringField("lastBuildDate", TypeAdapterUtils.toData(DateAdapter.class, object.lastBuildDate));
  }

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

  // field pubDate (mapped with "pubDate")
  if (object.pubDate!=null)  {
    fieldCount++;
    // using type adapter bind.rss.DateAdapter
    jacksonSerializer.writeStringField("pubDate", TypeAdapterUtils.toData(DateAdapter.class, object.pubDate));
  }

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

  // field articles (mapped with "item")
  if (object.articles!=null)  {
    fieldCount++;
    int n=object.articles.size();
    Article item;
    // write wrapper tag
    jacksonSerializer.writeFieldName("item");
    if (n>0) {
      jacksonSerializer.writeStartArray();
      for (int i=0; i<n; i++) {
        item=object.articles.get(i);
        if (item==null) {
          jacksonSerializer.writeString("null");
        } else {
          if (articleBindMap.serializeOnJacksonAsString(item, jacksonSerializer)==0) {
            jacksonSerializer.writeNullField("item");
          }
        }
      }
      jacksonSerializer.writeEndArray();
    } else {
      jacksonSerializer.writeString("");
    }
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 17
Source File: _JSR310DateTimeSerializer.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void serialize(TemporalAccessor value, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException {
    generator.writeString(ISOFormatter.format(value));
}
 
Example 18
Source File: AvailabilityTypeSerializer.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(AvailabilityType availabilityType, JsonGenerator jsonGenerator, SerializerProvider
        serializerProvider) throws IOException, JsonProcessingException {
    jsonGenerator.writeString(availabilityType.getText());
}
 
Example 19
Source File: FileSerializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(File value, JsonGenerator g, SerializerProvider provider) throws IOException {
    g.writeString(value.getAbsolutePath());
}
 
Example 20
Source File: TypeBase.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void serialize(JsonGenerator gen, SerializerProvider provider)
        throws IOException, JsonProcessingException
{
    gen.writeString(toCanonical());
}