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

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

Introduction

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

Prototype

public abstract void writeString(SerializableString text) throws IOException, JsonGenerationException;

Source Link

Document

Method similar to #writeString(String) , but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.

Usage

From source file:de.fraunhofer.iosb.ilt.sta.serialize.TimeValueSerializer.java

@Override
public void serialize(TimeValue value, JsonGenerator gen, SerializerProvider serializers)
        throws IOException, JsonProcessingException {
    if (value.asISO8601() == null) {
        gen.writeNull();/*from  w  ww.ja  va2  s . c om*/
    } else {
        gen.writeString(value.asISO8601());
    }
}

From source file:de.terrestris.shogun.serializer.DateSerializer.java

/**
 * Overwrite the original serialize and return a String representation of
 * the java.util.Date-instance.// w  ww  .ja  v a2 s  . c o m
 */
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

    DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    jgen.writeString(formatter.format(new Date(value.getTime())));
}

From source file:com.meltmedia.jackson.crypto.beans.Base64Serializer.java

@Override
public void serialize(String value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (value == null) {
        jgen.writeNull();// ww w  . jav a  2s.  c  om
    } else {
        jgen.writeString(encoder.encodeToString(value.getBytes()));
    }
}

From source file:net.solarnetwork.util.JodaDateTimeSerializer.java

@Override
public void serialize(DateTime o, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (o == null) {
        return;/*from  ww w.  j a v a 2s. c  om*/
    }
    generator.writeString(serializeWithFormatter(o));
}

From source file:net.solarnetwork.util.JodaLocalDateSerializer.java

@Override
public void serialize(LocalDate o, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (o == null) {
        return;//from ww  w  .  j  a  v  a2 s.  c o  m
    }
    generator.writeString(serializeWithFormatter(o));
}

From source file:net.solarnetwork.util.JodaLocalDateTimeSerializer.java

@Override
public void serialize(LocalDateTime o, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (o == null) {
        return;/*from   w  w w.  j  ava  2  s  .  c  o m*/
    }
    generator.writeString(serializeWithFormatter(o));
}

From source file:net.solarnetwork.util.JodaLocalTimeSerializer.java

@Override
public void serialize(LocalTime o, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    if (o == null) {
        return;//from   w  w  w . j a v a2s . c  o  m
    }
    generator.writeString(serializeWithFormatter(o));
}

From source file:co.centauri.json.JSONDateSerialize.java

@Override
public void serialize(Date t, JsonGenerator jg, SerializerProvider sp)
        throws IOException, JsonProcessingException {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    String formattedDate = dateFormat.format(t);
    jg.writeString(formattedDate);
}

From source file:com.infinities.nova.util.jackson.NullStringSerializer.java

@Override
public void serialize(String value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    if (value.equals(NULL_SUBSITUTE)) {
        jgen.writeNull();/*from  ww  w .j a v  a  2 s  . com*/
    } else {
        jgen.writeString(value);
    }

}

From source file:org.example.testcases.BasicTypesSerializer.java

private void writeObject(JsonGenerator jg, BasicTypes basicType) throws IOException {
    jg.writeStartObject();//from   w  ww. j  a  va  2s.c  o  m
    // write field aString...
    jg.writeFieldName("aString");
    jg.writeString(basicType.aString);
    // write field aBoolean...
    jg.writeFieldName("aBoolean");
    jg.writeBoolean(basicType.aBoolean);
    // write field aFloat...
    jg.writeFieldName("aFloat");
    jg.writeNumber(basicType.aFloat);
    // write field aDouble...
    jg.writeFieldName("aDouble");
    jg.writeNumber(basicType.aDouble);
    // write field aInt...
    jg.writeFieldName("aInt");
    jg.writeNumber(basicType.aInt);
    // write field aShort...
    jg.writeFieldName("aShort");
    jg.writeNumber(basicType.aShort);
    // write field aByte...
    jg.writeFieldName("aByte");
    jg.writeNumber(basicType.aByte);
    // done.
    jg.writeEndObject();
}