...
TAG_NAME | Name of the tag. For example currency, amount, Name, Voucher, Id, brand etc | ||||||||||||||||||||||||||||||||||||||||||||||||
MAP_KEY | Key to retrieve the correct component from the map. Example: HEADER or FILEDEF or RECORD_DEF or tag name of the parent record from which a child tag value can be obtained. HEADER holds the file source record. FILEDEF holds the current instance of JSONDocumenrFiller. RECORD_DEF holds the CDR_RECORD_DEF (with CODE = DETAIL) instance set up for this JSON Document export | ||||||||||||||||||||||||||||||||||||||||||||||||
VALUE_TYPE | Can be FIELD (if the value to print is a field of the map object) or METHOD (if the content is retrieved calling a specific method in the map object obtained via the key set in MAP_KEY). | ||||||||||||||||||||||||||||||||||||||||||||||||
FIELD_NAME | If the value type is FIELD then this specify the field to print in the JSON tag content. | ||||||||||||||||||||||||||||||||||||||||||||||||
METHOD_NAME | if the value type is METHOD, then this specify the method to invoke on the map object to retrieve the data to fill the content for the current tag. | ||||||||||||||||||||||||||||||||||||||||||||||||
JSON_DATA_TYPE | The data type with which the JSON field value should be represented while writing value to file. Possible value are OBJECT, ARRAY, STRING, NUMBER andBOOLEAN.
Please see: Value Formatter and How to use VALUE_FORMATTER and JSON_DATA_TYPE for more details Note: JSON Key names will always be surrounded by double quotes. This JSON_DATA_TYPE configuration settings are applicable only for values, not the keys.
| ||||||||||||||||||||||||||||||||||||||||||||||||
PARENT_ID | Defines the ID of the parent tag and therefore it is used to define the structure of the JSON-file. The parent ID for the root tag will be null. | ||||||||||||||||||||||||||||||||||||||||||||||||
FLUSH_CONTENT | if ‘Y’ the content generated in the outputStream will be flushed in the JSON-file when the end tag of the current tag is printed. | ||||||||||||||||||||||||||||||||||||||||||||||||
FORMATTER_ID | ID of appropriate VALUE_FORMATTER table entry that is suitable to format this field value. The value formatter used to format the JSON field value, before applying the JSON_DATA_TYPE (see ValueFormatter for more details). So, first the Value formatter is applied to the field value, and then the JSON_DATA_TYPE setting is applied. Please see: Value Formatter and How to use VALUE_FORMATTER and JSON_DATA_TYPE for more details | ||||||||||||||||||||||||||||||||||||||||||||||||
METHOD_INPUT | In some cases when the METHOD_NAME is invoked we also need some extra information that must be passed in the method. For instance in the cdr generation if we have a list of invoice detail lines inside the record tag we need to retrieve only the invoice detail lines related to that billing record and this can be done by defining in this field the tag name related to the object to pass: in this case it will be “Record”. | ||||||||||||||||||||||||||||||||||||||||||||||||
METHOD_INPUT_CLASS_NAME | This is the class name of the method_input field (“com.CDRator.billing.rating.BillingRecords” in this example). | ||||||||||||||||||||||||||||||||||||||||||||||||
SEQ_ORDER | If a tag has more than one child, here we can specify the preferred order to print them. | ||||||||||||||||||||||||||||||||||||||||||||||||
RELOAD_METHOD | If the tag to print is related to a list (i.e. a list of records) then it is possible to load them in multiple batches. In the JSON file generation when the content of the current batch has been printed then we try to retrieve further elements using the reload method if set. |
...
NAME | A unique name to distinguish different Formatters |
CODE | Formatter code |
DESCRIPTION | Describes the purpose of the formatter |
VALUE_CLASS | Defines the input for the formatter (i.e. java.util.Date or java.lang.Number or java.lang.String) Important Note: The formatter should be chosen based on the actual value type. So If the value to be formatter is a String, thentype is not compatible with the java type defined in VALUE_FORMATTER.VALUE_CLASS, the formatting fails and hence file generation fails.
|
FORMATTER_CLASS | Class used to format ( For example: com.CDRator.billing.utils.formatter.DateFormatter) |
FORMATTER_METHOD | Method name from the class defined in FORMATTER_CLASS, that should be executed to format the input value. Usually it is 'format'. |
FORMATTER_EXPRESSION | Pattern used to convert the object to formatted string. This is optional for the formatters that do not require a pattern to be defined. Examples:
|
NULL_VALUE | Value returned if the input object is null. This is optional and defaults to null. |
3.4.2 - How to use VALUE_FORMATTER and JSON_DATA_TYPE to get desired result
It is possible to represent the field values in a JSON Document in different ways. If the value should be represented as a string, it will be surrounded by double quotes. If it has to be written to the JSON file as a Number, no double quotes will be placed around the value. If the value should be represented as a boolean, the boolean equivalent of the actual field value (i.e. true/false) will be written to the JSON file. Consider the following scenarios:
(here the term 'actual field value' refers to the value obtained by calling a method or the value of the field from the Map object)
- The actual field value is a Number type , but would like to write it as a String in the JSON file. For example : Actual field value = 100, but we want the value written to the JSON file to be : "100"
- The actual field value is a Number with no decimals , but would like to write it as a float value in the JSON file. For example : Actual field value = 100, but we want the value written to the JSON file to be : 100.00
- The actual field value is a String/Number, but would like to write it as a Boolean in the JSON file. For example : Actual field value = "1" / 1, but we want the value written to the JSON file to be : true
- The actual field value is a String type and contains some characters that should be escaped to be JSON compatible. For example: Actual field value = "Value with "quotes"", but we want the value to be escaped properly before writing it to the JSON file.
During JSON file generation, the actual field value is always modified in this order, to get the desired result:
- First, the VALUE_FORMATTER corresponding to the JSON_TAG_DEF.FORMATTER_ID is applied to format the field value
- Then, JSON_TAG_DEF.JSON_DATA_TYPE configuration setting is used to convert the formatted field value to desired JSON type
So let us take a look at the scenarios we mentioned above and see how they can be achieved with proper configuration:
Scenario | Configuration |
---|---|
The actual field value is a Number type, but would like to write it as a String in the JSON file. For example : Actual field value = 100, but we want the value written to the JSON file to be : "100" | Value Formatter: No formatter (or) Number formatter with pattern containing no decimals JSON_DATA_TYPE: STRING |
The actual field value is a Number with no decimals, but would like to write it as a float value in the JSON file. For example : Actual field value = 100, but we want the value written to the JSON file to be : 100.00 | Value Formatter: Number formatter with pattern to convert to decimal format JSON_DATA_TYPE: NUMBER |
The actual field value is a String, but would like to write it as a Boolean in the JSON file. For example : Actual field value = "1"/1, but we want the value written to the JSON file to be : true | Value Formatter: No formatter needed JSON_DATA_TYPE: BOOLEAN |
The actual field value is a String type and contains some characters that should be escaped to be JSON compatible. For example: Actual field value = "Value with "quotes"", but we want the value to be escaped properly before writing it to the JSON file. | Value Formatter: JsonStringFormatter JSON_DATA_TYPE: STRING Actual field value = "Value with "quotes"" Result: "Value with \"quotes\"" |
4 - Example of Generation
...