*/
/*
- * JSON object wrapper with toll-free DDF bridging.
+ * JSON object wrapper with not-entirely-toll-free DDF bridging.
*/
#ifndef _UTIL_JSON_H_
using namespace shibsp;
-namespace gss_eap {
+namespace gss_eap_util {
class JSONObject;
+ class JSONException : public std::exception {
+ public:
+ JSONException(json_t *obj = NULL, json_type type = JSON_NULL);
+
+ ~JSONException(void) throw() {
+ json_decref(m_obj);
+ }
+
+ virtual const char *what(void) const throw() {
+ return m_reason.c_str();
+ }
+
+ private:
+ json_t *m_obj;
+ json_type m_type;
+ std::string m_reason;
+ };
+
class JSONIterator {
public:
JSONIterator(const JSONObject &obj);
static JSONObject object(void);
static JSONObject array(void);
static JSONObject null(void);
+ static JSONObject ddf(DDF &value);
char *dump(size_t flags = 0) const;
- void dump(FILE *fp, size_t flags = 0) const;
+ void dump(FILE *fp, size_t flags = JSON_INDENT(4)) const;
json_type type(void) const { return json_typeof(m_obj); }
size_t size(void) const;
JSONObject(void);
- JSONObject(DDF &value);
JSONObject(const char *value);
JSONObject(json_int_t value);
JSONObject(double value);
json_int_t integer(void) const;
double real(void) const;
double number(void) const;
- bool isnull(void) const;
DDF ddf(void) const;
+ bool isObject(void) const;
+ bool isArray(void) const;
+ bool isString(void) const;
+ bool isInteger(void) const;
+ bool isNumber(void) const;
+ bool isBoolean(void) const;
+ bool isNull(void) const;
+
~JSONObject(void)
{
if (m_obj != NULL)
}
}
- JSONObject(json_t *obj, bool retain);
+ JSONObject(json_t *obj, bool retain = true);
json_t *m_obj;
};