public class JsonWritingUtils extends Object
Note: This class is for internal use only and subject to backward incompatible change at any time.
| Constructor and Description |
|---|
JsonWritingUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
shouldWriteField(String fieldName)
Indicates whether the given field name must be written or not.
|
static void |
writeMapEntries(JsonGenerator generator,
Map<?,?> map)
Writes entries of the map as fields.
|
static void |
writeMapStringFields(JsonGenerator generator,
String fieldName,
Map<String,String> map)
Writes a map as String fields to the generator if and only if the
fieldName
and values are not null. |
static void |
writeMapStringFields(JsonGenerator generator,
String fieldName,
Map<String,String> map,
boolean lowerCaseKeys)
Writes a map as String fields to the generator if and only if the
fieldName
and values are not null. |
static void |
writeNumberField(JsonGenerator generator,
String fieldName,
int fieldValue)
Writes the field to the generator if and only if the
fieldName is not null. |
static void |
writeNumberField(JsonGenerator generator,
String fieldName,
long fieldValue)
Writes the field to the generator if and only if the
fieldName is not null. |
static void |
writeObject(JsonGenerator generator,
Object value)
Helper method to try to call appropriate write method for given
untyped Object.
|
static void |
writeStringArrayField(JsonGenerator generator,
String fieldName,
String[] fieldValues)
Writes an array of strings to the generator if and only if the
fieldName
and values are not null. |
static void |
writeStringField(JsonGenerator generator,
String fieldName,
String fieldValue)
Writes the field to the generator if and only if the
fieldName and
fieldValue are not null. |
public static void writeMapEntries(JsonGenerator generator, Map<?,?> map) throws IOException, JsonMappingException
generator - the JsonGenerator to produce JSON contentmap - map whose entries are written as JSON field/valuesIOException - if an I/O error occursJsonMappingException - when problem to convert map values of type Object into JSONpublic static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String,String> map) throws IOException, JsonMappingException
fieldName
and values are not null.generator - the JsonGenerator to produce JSON contentfieldName - name of the JSON property to write the map content undermap - map whose entries are written as JSON field/valuesIOException - if an I/O error occursJsonMappingException - when problem to convert map values of type Object into JSONpublic static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String,String> map, boolean lowerCaseKeys) throws IOException, JsonMappingException
fieldName
and values are not null.generator - the JsonGenerator to produce JSON contentfieldName - name of the JSON property to write the map content undermap - map whose entries are written as JSON field/valueslowerCaseKeys - when true, the map keys will be written in lower case.IOException - if an I/O error occursJsonMappingException - when problem to convert map values of type Object into JSONpublic static void writeStringArrayField(JsonGenerator generator, String fieldName, String[] fieldValues) throws IOException
fieldName
and values are not null.generator - the JsonGenerator to produce JSON contentfieldName - the field namefieldValues - the field valuesIOException - if an I/O error occurspublic static void writeStringField(JsonGenerator generator, String fieldName, String fieldValue) throws IOException
fieldName and
fieldValue are not null.generator - the JsonGenerator to produce JSON contentfieldName - the field namefieldValue - the field valueIOException - if an I/O error occurspublic static void writeNumberField(JsonGenerator generator, String fieldName, int fieldValue) throws IOException
fieldName is not null.generator - the JsonGenerator to produce JSON contentfieldName - the field namefieldValue - the field valueIOException - if an I/O error occurspublic static void writeNumberField(JsonGenerator generator, String fieldName, long fieldValue) throws IOException
fieldName is not null.generator - the JsonGenerator to produce JSON contentfieldName - the field namefieldValue - the field valueIOException - if an I/O error occurspublic static boolean shouldWriteField(String fieldName)
fieldName - the field nametrue if the field should be written, false otherwiseLogstashCommonFieldNames.IGNORE_FIELD_INDICATORpublic static void writeObject(JsonGenerator generator, Object value) throws IOException
JsonGenerator.writeObject(Object) if the value
cannot be efficiently handled by this method.generator - the JsonGenerator to produce JSON contentvalue - Value to writeIOException - if there is either an underlying I/O problem or encoding
issue at format layerCopyright © 2013–2021. All rights reserved.