Package net.logstash.logback.composite
Class JsonWritingUtils
java.lang.Object
net.logstash.logback.composite.JsonWritingUtils
Utilities for writing JSON
Note: This class is for internal use only and subject to backward incompatible change at any time.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 thefieldName
and values are notnull
.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 thefieldName
and values are notnull
.static void
writeNumberField
(JsonGenerator generator, String fieldName, int fieldValue) Writes the field to the generator if and only if thefieldName
is notnull
.static void
writeNumberField
(JsonGenerator generator, String fieldName, long fieldValue) Writes the field to the generator if and only if thefieldName
is notnull
.static void
writeStringArrayField
(JsonGenerator generator, String fieldName, String[] fieldValues) Writes an array of strings to the generator if and only if thefieldName
and values are notnull
.static void
writeStringField
(JsonGenerator generator, String fieldName, String fieldValue) Writes the field to the generator if and only if thefieldName
andfieldValue
are notnull
.
-
Constructor Details
-
JsonWritingUtils
public JsonWritingUtils()
-
-
Method Details
-
writeMapEntries
public static void writeMapEntries(JsonGenerator generator, Map<?, ?> map) throws IOException, JsonMappingExceptionWrites entries of the map as fields.- Parameters:
generator
- theJsonGenerator
to produce JSON contentmap
- map whose entries are written as JSON field/values- Throws:
IOException
- if an I/O error occursJsonMappingException
- when problem to convert map values of type Object into JSON
-
writeMapStringFields
public static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map) throws IOException, JsonMappingExceptionWrites a map as String fields to the generator if and only if thefieldName
and values are notnull
.- Parameters:
generator
- theJsonGenerator
to produce JSON contentfieldName
- name of the JSON property to write the map content undermap
- map whose entries are written as JSON field/values- Throws:
IOException
- if an I/O error occursJsonMappingException
- when problem to convert map values of type Object into JSON
-
writeMapStringFields
public static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map, boolean lowerCaseKeys) throws IOException, JsonMappingExceptionWrites a map as String fields to the generator if and only if thefieldName
and values are notnull
.- Parameters:
generator
- theJsonGenerator
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.- Throws:
IOException
- if an I/O error occursJsonMappingException
- when problem to convert map values of type Object into JSON
-
writeStringArrayField
public static void writeStringArrayField(JsonGenerator generator, String fieldName, String[] fieldValues) throws IOException Writes an array of strings to the generator if and only if thefieldName
and values are notnull
.- Parameters:
generator
- theJsonGenerator
to produce JSON contentfieldName
- the field namefieldValues
- the field values- Throws:
IOException
- if an I/O error occurs
-
writeStringField
public static void writeStringField(JsonGenerator generator, String fieldName, String fieldValue) throws IOException Writes the field to the generator if and only if thefieldName
andfieldValue
are notnull
.- Parameters:
generator
- theJsonGenerator
to produce JSON contentfieldName
- the field namefieldValue
- the field value- Throws:
IOException
- if an I/O error occurs
-
writeNumberField
public static void writeNumberField(JsonGenerator generator, String fieldName, int fieldValue) throws IOException Writes the field to the generator if and only if thefieldName
is notnull
.- Parameters:
generator
- theJsonGenerator
to produce JSON contentfieldName
- the field namefieldValue
- the field value- Throws:
IOException
- if an I/O error occurs
-
writeNumberField
public static void writeNumberField(JsonGenerator generator, String fieldName, long fieldValue) throws IOException Writes the field to the generator if and only if thefieldName
is notnull
.- Parameters:
generator
- theJsonGenerator
to produce JSON contentfieldName
- the field namefieldValue
- the field value- Throws:
IOException
- if an I/O error occurs
-
shouldWriteField
Indicates whether the given field name must be written or not. A field should be written if its name is not null and not ignored.- Parameters:
fieldName
- the field name- Returns:
true
if the field should be written,false
otherwise- See Also:
-