List of usage examples for com.fasterxml.jackson.core JsonGenerator writeRawValue
public abstract void writeRawValue(String text) throws IOException, JsonGenerationException;
From source file:com.googlecode.wickedcharts.highcharts.jackson.FunctionSerializer.java
@Override public void serialize(final Function value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { // raw values are needed // otherwise the js function can not be evaluated jgen.writeRawValue(value.getFunction()); }
From source file:it.reply.orchestrator.resource.common.CustomSerializer.java
@Override public void serialize(Map<String, String> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject();//from w w w.j a va 2s. c om for (Map.Entry<String, String> e : value.entrySet()) { jgen.writeFieldName(e.getKey()); // Write value as raw data, since it's already JSON text jgen.writeRawValue(e.getValue()); } jgen.writeEndObject(); }
From source file:com.googlecode.wickedcharts.highcharts.jackson.HexColorReferenceSerializer.java
@Override protected void serializeIfNotNull(final HexColor color, final JsonGenerator jgen, final SerializerProvider provider) throws JsonGenerationException, IOException { if (color.getBrightness() == null) { jgen.writeString(color.getHexColor()); } else {//ww w .j a va2 s . co m String colorString = brighten("\"" + color.getHexColor() + "\"", color.getBrightness()); jgen.writeRawValue(colorString); } }
From source file:io.gravitee.definition.jackson.datatype.plugins.resource.ser.ResourceSerializer.java
@Override public void serialize(Resource resource, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject();// www .ja va 2s . c o m jgen.writeStringField("name", resource.getName()); jgen.writeStringField("type", resource.getType()); jgen.writeBooleanField("enabled", resource.isEnabled()); jgen.writeFieldName("configuration"); jgen.writeRawValue(resource.getConfiguration()); jgen.writeEndObject(); }
From source file:com.googlecode.wickedcharts.highcharts.jackson.SimpleColorReferenceSerializer.java
@Override protected void serializeIfNotNull(final SimpleColor color, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { if (color.getBrightness() == null) { jgen.writeString(toHexString(color.getColor())); } else {/* w w w . java2 s . c o m*/ String colorString = brighten("\"" + toHexString(color.getColor()) + "\"", color.getBrightness()); jgen.writeRawValue(colorString); } }
From source file:com.arpnetworking.logback.serialization.ObjectAsJsonSerialziationStrategy.java
/** * Serialize an event./* w w w . ja va2s.c o m*/ * * @param event The event. * @param eventName The event name. * @param jsonData The message data as serialized JSON. * @return Serialization of message as a <code>String</code>. */ public String serialize(final ILoggingEvent event, final String eventName, final String jsonData) { final StringWriter jsonWriter = new StringWriter(); try { final JsonGenerator jsonGenerator = _jsonFactory.createGenerator(jsonWriter); // Start wrapper startStenoWrapper(event, eventName, jsonGenerator, _objectMapper); // Write event data jsonGenerator.writeFieldName("data"); if (jsonData == null) { jsonGenerator.writeStartObject(); jsonGenerator.writeEndObject(); } else { jsonGenerator.writeRawValue(jsonData); } // TODO(vkoskela): Support writing null objects as-is via configuration [MAI-333] // e.g. "data":null -- although this is not supported by the current Steno specification // Output throwable writeThrowable(event.getThrowableProxy(), jsonGenerator, _objectMapper); // End wrapper endStenoWrapper(event, eventName, jsonGenerator, _objectMapper); } catch (final IOException e) { return "Unknown exception: " + e.getMessage(); } return jsonWriter.toString(); }
From source file:com.googlecode.wickedcharts.highcharts.jackson.RgbaColorReferenceSerializer.java
@Override protected void serializeIfNotNull(final RgbaColor color, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { if (color.getBrightness() == null) { jgen.writeString(String.format(Locale.ENGLISH, RGBA, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));/*from www. ja va2 s . c o m*/ } else { String colorString = brighten("\"" + String.format(Locale.ENGLISH, RGBA, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()) + "\"", color.getBrightness()); jgen.writeRawValue(colorString); } }
From source file:com.googlecode.wickedcharts.highcharts.jackson.CssStyleSerializer.java
@Override public void serialize(final CssStyle value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { StringBuilder cssStyleBuilder = new StringBuilder(); cssStyleBuilder.append("{"); for (Entry<String, String> property : value.getProperties().entrySet()) { cssStyleBuilder.append("\"" + property.getKey() + "\": \"" + property.getValue() + "\","); }/*from w w w .j av a2s . c om*/ int lastCommaPosition = cssStyleBuilder.lastIndexOf(","); if (lastCommaPosition != -1) { cssStyleBuilder.deleteCharAt(lastCommaPosition); } cssStyleBuilder.append(" }"); jgen.writeRawValue(cssStyleBuilder.toString()); }
From source file:com.googlecode.wickedcharts.highcharts.jackson.DateTimeLabelFormatSerializer.java
@Override public void serialize(final DateTimeLabelFormat value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { StringBuilder dateTimeFormatBuilder = new StringBuilder(); dateTimeFormatBuilder.append("{"); for (Entry<DateTimeProperties, String> property : value.getProperties().entrySet()) { dateTimeFormatBuilder.append(" " + property.getKey().toCode() + ": '" + property.getValue() + "',"); }/*from w w w . jav a2s. c o m*/ int lastCommaPosition = dateTimeFormatBuilder.lastIndexOf(","); if (lastCommaPosition != -1) { dateTimeFormatBuilder.deleteCharAt(lastCommaPosition); } dateTimeFormatBuilder.append(" }"); jgen.writeRawValue(dateTimeFormatBuilder.toString()); }
From source file:com.arpnetworking.logback.serialization.MapOfJsonSerialziationStrategy.java
/** * Serialize an event./*w w w . jav a 2 s . c o m*/ * * @param event The event. * @param eventName The event name. * @param map The message key to json-value pairs. * @return Serialization of message as a <code>String</code>. */ public String serialize(final ILoggingEvent event, final String eventName, final Map<String, String> map) { final StringWriter jsonWriter = new StringWriter(); try { final JsonGenerator jsonGenerator = _jsonFactory.createGenerator(jsonWriter); // Start wrapper startStenoWrapper(event, eventName, jsonGenerator, _objectMapper); // Write event data jsonGenerator.writeObjectFieldStart("data"); if (map != null) { for (final Map.Entry<String, String> entry : map.entrySet()) { if (entry.getValue() == null) { jsonGenerator.writeObjectField(entry.getKey(), null); } else { jsonGenerator.writeFieldName(entry.getKey()); jsonGenerator.writeRawValue(entry.getValue()); } } } jsonGenerator.writeEndObject(); // End 'data' field // Output throwable writeThrowable(event.getThrowableProxy(), jsonGenerator, _objectMapper); // End wrapper endStenoWrapper(event, eventName, jsonGenerator, _objectMapper); } catch (final IOException e) { return "Unknown exception: " + e.getMessage(); } return jsonWriter.toString(); }