Poco::Data

class JSONRowFormatter

Library: Data
Package: DataCore
Header: Poco/Data/JSONRowFormatter.h

Description

Class for JSON formatting of data rows.

Formatter can be configured to operate in four modes (and certain combinations thereof) :

  • small (condensed mode, only array of values)

Example:
{
 [["Simpson", "Bart", "Springfield", 12],
 ["Simpson", "Lisa", "Springfield", 10]]
}

row count (total row count provided)

Example:
{
 "count":2,
 [["Simpson", "Bart", "Springfield", 12],
  ["Simpson", "Lisa", "Springfield", 10]]
}

column names (column names provided as a string array)

Example:
{
 "names":["LastName", "FirstName", "Address", "Age"],
 [["Simpson", "Bart", "Springfield", 12],
 ["Simpson", "Lisa", "Springfield", 10]]
}

full (total row count, column names provided in every row of data)

Example:
{
 "count":2,
  [
   {"LastName": "Simpson", "FirstName": "Bart", "Address": "Springfield", "Age": 12},
   {"LastName": "Simpson", "FirstName": "Lisa", "Address": "Springfield", "Age": 10}
  ]
}

Total row count will be specified by the Poco::SQLRecordSet. Note, however, that this is not possible to do accurately in case of result set paging. For those cases, there is setTotalRowCount() member function, which allows to explicitly set the total row count. If the total row count is preset on the formatter, the Data framework shall not interfere.

Inheritance

Direct Base Classes: RowFormatter

All Base Classes: RowFormatter

Member Summary

Member Functions: formatNames, formatValues, isFull, isSmall, printColumnNames, printRowCount, setJSONMode

Inherited Functions: adjustPrefix, formatNames, formatValues, getMode, getTotalRowCount, postfix, prefix, reset, rowCount, setMode, setPostfix, setPrefix, setTotalRowCount, toString

Constructors

JSONRowFormatter

JSONRowFormatter(
    int mode = (JSON_FMT_MODE_COLUMN_NAMES | JSON_FMT_MODE_SMALL)
);

Creates a new JSONRowFormatter.

Destructor

~JSONRowFormatter virtual

~JSONRowFormatter();

Destroys the JSONRowFormatter.

Member Functions

formatNames virtual

std::string & formatNames(
    const NameVecPtr pNames,
    std::string & formattedNames
);

Formats names.

formatValues virtual

std::string & formatValues(
    const ValueVec & vals,
    std::string & formattedValues
);

isFull inline

bool isFull() const;

Returns true if full mode formatting is enabled, false otherwise.

isSmall inline

bool isSmall() const;

Returns true if compact mode formatting is enabled, false otherwise.

printColumnNames inline

bool printColumnNames() const;

Returns true if column names printing is enabled, false otherwise.

printRowCount inline

bool printRowCount() const;

Returns true if row count printing is enabled, false otherwise.

setJSONMode

void setJSONMode(
    int mode
);

Sets the mode. Valid mode values are:

JSON_FMT_MODE_SMALL
JSON_FMT_MODE_ROW_COUNT
JSON_FMT_MODE_COLUMN_NAMES
JSON_FMT_MODE_FULL

Variables

JSON_FMT_MODE_COLUMN_NAMES static

static const int JSON_FMT_MODE_COLUMN_NAMES = 4;

JSON_FMT_MODE_FULL static

static const int JSON_FMT_MODE_FULL = 8;

JSON_FMT_MODE_ROW_COUNT static

static const int JSON_FMT_MODE_ROW_COUNT = 2;

JSON_FMT_MODE_SMALL static

static const int JSON_FMT_MODE_SMALL = 1;