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 booleanshouldWriteField(String fieldName) Indicates whether the given field name must be written or not.static voidwriteMapEntries(JsonGenerator generator, Map<?, ?> map) Writes entries of the map as fields.static voidwriteMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map) Writes a map as String fields to the generator if and only if thefieldNameand values are notnull.static voidwriteMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map, boolean lowerCaseKeys) Writes a map as String fields to the generator if and only if thefieldNameand values are notnull.static voidwriteNumberField(JsonGenerator generator, String fieldName, int fieldValue) Writes the field to the generator if and only if thefieldNameis notnull.static voidwriteNumberField(JsonGenerator generator, String fieldName, long fieldValue) Writes the field to the generator if and only if thefieldNameis notnull.static voidwriteStringArrayField(JsonGenerator generator, String fieldName, String[] fieldValues) Writes an array of strings to the generator if and only if thefieldNameand values are notnull.static voidwriteStringField(JsonGenerator generator, String fieldName, String fieldValue) Writes the field to the generator if and only if thefieldNameandfieldValueare notnull.
-
Constructor Details
-
JsonWritingUtils
public JsonWritingUtils()
-
-
Method Details
-
writeMapEntries
Writes entries of the map as fields.- Parameters:
generator- theJsonGeneratorto produce JSON contentmap- map whose entries are written as JSON field/values
-
writeMapStringFields
public static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map) Writes a map as String fields to the generator if and only if thefieldNameand values are notnull.- Parameters:
generator- theJsonGeneratorto produce JSON contentfieldName- name of the JSON property to write the map content undermap- map whose entries are written as JSON field/values
-
writeMapStringFields
public 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 thefieldNameand values are notnull.- Parameters:
generator- theJsonGeneratorto 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.
-
writeStringArrayField
public static void writeStringArrayField(JsonGenerator generator, String fieldName, String[] fieldValues) Writes an array of strings to the generator if and only if thefieldNameand values are notnull.- Parameters:
generator- theJsonGeneratorto produce JSON contentfieldName- the field namefieldValues- the field values
-
writeStringField
Writes the field to the generator if and only if thefieldNameandfieldValueare notnull.- Parameters:
generator- theJsonGeneratorto produce JSON contentfieldName- the field namefieldValue- the field value
-
writeNumberField
Writes the field to the generator if and only if thefieldNameis notnull.- Parameters:
generator- theJsonGeneratorto produce JSON contentfieldName- the field namefieldValue- the field value
-
writeNumberField
Writes the field to the generator if and only if thefieldNameis notnull.- Parameters:
generator- theJsonGeneratorto produce JSON contentfieldName- the field namefieldValue- the field value
-
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:
trueif the field should be written,falseotherwise- See Also:
-