See: com.google.gson.Gson
Usage
The simplest usage is to use the class to create a Gson instance configured for use with EasySMF, using the default options:
Gson gson = new EasySmfGsonBuilder().createGson(); String json = gson.toJson(mySmfRecord);
You can also access the underlying GsonBuilder to specify any Gson options required:
GsonBuilder gsonBuilder = new EasySmfGsonBuilder().getGsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); String json = gson.toJson(mySmfRecord);
Options can be chained in fluent style, so the example above can be re-written as:
Gson gson = new EasySmfGsonBuilder() .getGsonBuilder() // working with GsonBuilder options from here .setPrettyPrinting() .create(); String json = gson.toJson(mySmfRecord);
Customizing the Output
EasySmfGsonBuilder provides several ways to customize the output.exclude(String)
excludes a section or field by nameexclude(Class, String)
excludes a section or field of a particular class by nameinclude(String)
always includes a section or field by name. This means that the various exclude options can be overridden on a field by field basis.include(Class, String)
always includes a section or field of a particular class by name This means that the various exclude options can be overridden on a field by field basis.includeZeroValues(boolean)
indicates whether fields with zero values should be included. Default: true. When false, this can be overridden for individual fields usinginclude(String)
includeEmptyStrings(boolean)
indicates whether fields with empty string values should be included. Default: true. When false, this can be overridden for individual fields usinginclude(String)
alias(Class, String, String)
use a different name for a field of a classaddEntry(Class, String, Object)
allows you to add a fixed value to each entry generated for a particular classcalculateEntry(Class, String, Function)
allows you to provide a function or lambda to add a calculated value to each entry for a class.- EasySMF provides the data from some fields in multiple formats. For example, CPU time
is usually available as a java.time.Duration, a value converted to seconds, and the unconverted RawValue.
The following options allow you to select which of these values should be included across all records
and sections. By default, the values in seconds are included in the generated JSON.
includeRawValues(boolean)
- default: falsedurationAsDuration(boolean)
- default: falsedurationAsSeconds(boolean)
- default: true
CICS Specific Options
CICS transactions are different to other SMF data because the available fields are defined by a dictionary. CICS transaction information also produces a large quantity of output. For these reasons there are several options specific to CICS transaction information:
cicsExcludeGroup(String)
Exclude a group of transactions by owner e.g. "DFHWEBB"cicsVerbose(boolean)
- default: falseVerbose format includes all the field identification information in the JSON output eg:
"values": [ { "cmodHead": "START", "cmodName": "DFHCICS", "ident": "T005", "value": "2019-10-29T14:02:54.383214723Z" }, { "cmodHead": "STOP", "cmodName": "DFHCICS", "ident": "T006", "value": "2019-10-29T14:02:54.383481508Z" }, ...
Non-verbose format only includes field names:"start": "2019-10-29T14:02:54.383214723Z", "stop": "2019-10-29T14:02:54.383481508Z", ...
cicsClockDetail(boolean)
- default: trueIndicates whether CICS clock fields are complex values including the timer value, count and flags fields. To reduce the amount of output set this to false and only the timer value in seconds will be provided.
Type Adapters
EasySmfGsonBuilder sets up TypeAdapters for the following data types used in EasySMF:
- EasySMF records and sections
- java.time Classes:
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- OffsetDateTime
- OffsetTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
- byte[] byte array
It also provides the option to modify the formatting for floating point values to avoid the use of scientific notation which makes the JSON more (human) readable.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd a fixed value to the generated JSON for every record or section of a particular typeRename a section or field from a specific record or section type.avoidScientificNotation
(boolean value) Use decimal numbers instead of scientific notation for a wider range of double and float values (true/false).<T extends SmfData>
EasySmfGsonBuildercalculateEntry
(Class<T> targetType, String name, Function<T, Object> value) Add a calculated value to the JSON for every record or section of a particular typecicsClockDetail
(boolean value) Include detailed data for CICS clocks (true/false).cicsExcludeGroup
(String name) Exclude a group of fields from CICS transaction datacicsVerbose
(boolean value) Export CICS transaction data in verbose format (true/false).Create the Gson instance configured to serialize SMF data from EasySMF records and sections into JSON.decimalPlaces
(int value) Set the maximum number of decimal places to be used in double and floating point numbers (1-9).durationAsDuration
(boolean value) Indicate whether Duration entries for time values (CPU time etc) should be included.durationAsSeconds
(boolean value) Indicate whether time values (CPU time etc) converted to seconds should be included.exclude
(MonitoringField field) Exclude a CICS monitoring field.Exclude a section or field from a specific record or section type by name.Exclude a section or field by name.Get the underlying GsonBuilder for this class, allowing additional GsonBuilder options to be specified.include
(MonitoringField field) Include a CICS monitoring field.Include a section or field from a specific record or section type by name.Include a section or field by name.includeDeprecated
(boolean value) Indicate whether fields that are marked as Deprecated in the EasySMF API should be includedincludeEmptyStrings
(boolean value) Include fields with empty strings in the output (true/false).includeRawValues
(boolean value) Indicate whether the ...RawValue() entries should be included in the output where they are provided, eg java.time entries where the value is converted to Duration, LocalDateTime, Seconds etc.includeSectionType
(boolean value) Indicate whether a "sectionType" entry should be added to each section with name of the section class.includeUnsetFlags
(boolean value) Indicate whether flags returned as boolean values should be included if the flag is not set (i.e. the value is zero/false)includeZeroValues
(boolean value) Include fields with zero values in the output (true/false).Call setPrettyPrinting() on the underlying GsonBuildertimesAsEpochSeconds
(boolean value) Indicate whether time values (ZonedDateTime, OffsetDateTime, Instant) should be expressed as seconds from the Unix epoch
-
Constructor Details
-
EasySmfGsonBuilder
public EasySmfGsonBuilder()Create an EasySmfGsonBuilder instance
-
-
Method Details
-
getGsonBuilder
Get the underlying GsonBuilder for this class, allowing additional GsonBuilder options to be specified.- Returns:
- GsonBuilder
-
createGson
Create the Gson instance configured to serialize SMF data from EasySMF records and sections into JSON.- Returns:
- the Gson instance
-
includeRawValues
Indicate whether the ...RawValue() entries should be included in the output where they are provided, eg java.time entries where the value is converted to Duration, LocalDateTime, Seconds etc.Default: false
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
includeSectionType
Indicate whether a "sectionType" entry should be added to each section with name of the section class. Useful when the field name doesn't specifically indicate the type e.g. CICS statistics sections where the sections are specialized types of a base class.Default: false
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
durationAsDuration
Indicate whether Duration entries for time values (CPU time etc) should be included. See alsodurationAsSeconds(boolean)
Default: false
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
durationAsSeconds
Indicate whether time values (CPU time etc) converted to seconds should be included. See alsodurationAsDuration(boolean)
Default: true
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
timesAsEpochSeconds
Indicate whether time values (ZonedDateTime, OffsetDateTime, Instant) should be expressed as seconds from the Unix epochDefault: false
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
includeUnsetFlags
Indicate whether flags returned as boolean values should be included if the flag is not set (i.e. the value is zero/false)Default: true - values are always included
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
includeDeprecated
Indicate whether fields that are marked as Deprecated in the EasySMF API should be includedDefault: false
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
setPrettyPrinting
Call setPrettyPrinting() on the underlying GsonBuilder- Returns:
- this EasySmfGsonBuilder
-
cicsVerbose
Export CICS transaction data in verbose format (true/false).Verbose format includes the owner name (e.g. DFHCICS), field identifier (e.g. T005) and informal name (e.g. START). Otherwise only the informal name is included, or the informal name combined with the identifier if the informal name is not unique (e.g. SCUSRHWM_A033).
- Parameters:
value
- true/false, default false.- Returns:
- this EasySmfGsonBuilder
-
includeZeroValues
Include fields with zero values in the output (true/false).SMF data typically includes many fields with zero values. To reduce the amount of JSON generated, set includeZeroValues(false) to omit zero values from the generated JSON.
- Parameters:
value
- true/false, default true.- Returns:
- this EasySmfGsonBuilder
-
includeEmptyStrings
Include fields with empty strings in the output (true/false).SMF data can include many fields with empty string values. To reduce the amount of JSON generated, set includeEmptyStrings(false) to omit empty string values from the generated JSON.
- Parameters:
value
- true/false, default true.- Returns:
- this EasySmfGsonBuilder
-
cicsClockDetail
Include detailed data for CICS clocks (true/false).CICS clock values include a timer value, a count field and flags. To reduce the amount of JSON generated, you can set cicsClockDetail to false and only the timer value will be included in the output.
e.g.
- cicsClockDetail(true):
"usrcput":{"timerSeconds":0.000274924,"count":1,"flags":"0x00"}
- cicsClockDetail(false):
"usrcputSeconds":0.000274924
Note: You can only
addEntry(Class, String, Object)
orcalculateEntry(Class, String, Function)
values for CICS clocks if cicsClockDetail is true.- Parameters:
value
- true/false, default true.- Returns:
- this EasySmfGsonBuilder
- cicsClockDetail(true):
-
cicsExcludeGroup
Exclude a group of fields from CICS transaction data- Parameters:
name
- The owner name of the group e.g. "DFHWEBB"- Returns:
- this EasySmfGsonBuilder
-
exclude
Exclude a section or field by name. The name is the name of the section or field in the parent section, e.g. smf30cpt or excpSections- Parameters:
name
- The name of the section or field- Returns:
- this EasySmfGsonBuilder
-
exclude
Exclude a section or field from a specific record or section type by name.- Parameters:
targetType
- The class for the exclusion, e.g. ProcessorAccountingSection.class or Smf30Record.classname
- The name of the section or field e.g. smf30cpt or excpSections- Returns:
- this EasySmfGsonBuilder
-
exclude
Exclude a CICS monitoring field.- Parameters:
field
- the CICSMonitoringField
- Returns:
- this EasySmfGsonBuilder
-
include
Include a section or field by name. The name is the name of the section or field in the parent section, e.g. smf30cpt or excpSections. Include overrides any exclude options e.g.cicsExcludeGroup(String)
includeZeroValues(boolean)
,durationAsDuration(boolean)
- Parameters:
name
- The name of the section or field- Returns:
- this EasySmfGsonBuilder
-
include
Include a CICS monitoring field.- Parameters:
field
- the CICSMonitoringField
- Returns:
- this EasySmfGsonBuilder
-
include
Include a section or field from a specific record or section type by name. Include overrides any exclude options e.g.cicsExcludeGroup(String)
includeZeroValues(boolean)
,durationAsDuration(boolean)
- Parameters:
targetType
- The class for the exclusion, e.g. ProcessorAccountingSection.class or Smf30Record.classname
- The name of the section or field e.g. smf30cpt or excpSections- Returns:
- this EasySmfGsonBuilder
-
alias
public EasySmfGsonBuilder alias(Class<? extends SmfData> targetType, String fromName, String toName) Rename a section or field from a specific record or section type.- Parameters:
targetType
- The class for the alias, e.g. ProcessorAccountingSection.class or Smf30Record.classfromName
- The name of the section or field e.g. smf30cpt or excpSectionstoName
- The desired name of the section or field- Returns:
- this EasySmfGsonBuilder
-
avoidScientificNotation
Use decimal numbers instead of scientific notation for a wider range of double and float values (true/false). This makes values easier to read by a human, particularly when looking at small numbers e.g. transaction CPU times.Default: false - Gson default scientific notation will be used
- Parameters:
value
- true or false- Returns:
- this EasySmfGsonBuilder
-
decimalPlaces
Set the maximum number of decimal places to be used in double and floating point numbers (1-9). ImpliesavoidScientificNotation(true)
.Default: no maximum - default formatting will be used.
- Parameters:
value
- maximum number of decimal places, from 1 to 9.- Returns:
- this EasySmfGsonBuilder
-
addEntry
Add a fixed value to the generated JSON for every record or section of a particular typeGson gson = new EasySmfGsonBuilder() .addEntry(Smf7Record.class, "event", "SMF Data Lost") .createGson();
- Parameters:
targetType
- The class to to add data to, e.g. Smf7Record.classname
- The JSON entry name e.g. "event"value
- The JSON entry value e.g. "SMF data lost"- Returns:
- this EasySmfGsonBuilder
-
calculateEntry
public <T extends SmfData> EasySmfGsonBuilder calculateEntry(Class<T> targetType, String name, Function<T, Object> value) Add a calculated value to the JSON for every record or section of a particular typeGson gson = new EasySmfGsonBuilder() .calculateEntry(Smf30Record.class, "elapsed", r30 -> { return Duration.between( r30.identificationSection().smf30std() .atTime(r30.identificationSection().smf30sit()), r30.smfDate());} ) .createGson();
- Type Parameters:
T
- Represents the type of the object input to the calculation function (the same class as the targetType parameter)- Parameters:
targetType
- The class to to add data to, e.g. Smf30Record.classname
- The JSON entry name e.g. "day_of_week"value
- The calculation to produce the value e.g. r30 -> { return r30.smfDate().getDayOfWeek();}- Returns:
- this EasySmfGsonBuilder
-