1 /* This file is part of qjson
3 * Copyright (C) 2009 Till Adam <adam@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef QJSON_SERIALIZER_H
22 #define QJSON_SERIALIZER_H
24 #include "qjson_export.h"
32 * @brief How the indentation should work.
34 * none (default) : { "foo" : 0, "foo1" : 1, "foo2" : [ { "foo3" : 3, "foo4" : 4 } ] }
36 * compact : {"foo":0,"foo1":1,"foo2":[{"foo3":3,"foo4":4}]}
38 * minimum : { "foo" : 0, "foo1" : 1, "foo2" : [
39 * { "foo3" : 3, "foo4" : 4 }
43 * "foo" : 0, "foo1" : 1, "foo2" : [
45 * "foo3" : 3, "foo4" : 4
68 * @brief Main class used to convert QVariant objects to JSON data.
70 * QVariant objects are converted to a string containing the JSON data.
71 * If QVariant object is empty or not valid a <em>null</em> json object is returned.
73 class QJSON_EXPORT Serializer {
79 * This method generates a textual JSON representation and outputs it to the
80 * passed in I/O Device.
81 * @param variant The JSON document in its in-memory representation as generated by the
83 * @param out Input output device
84 * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true
86 void serialize( const QVariant& variant, QIODevice* out, bool* ok = 0);
89 * This is a method provided for convenience. It turns the passed in in-memory
90 * representation of the JSON document into a textual one, which is returned.
91 * If the returned string is empty, the document was empty. If it was null, there
92 * was a parsing error.
94 * @param variant The JSON document in its in-memory representation as generated by the
98 QByteArray serialize( const QVariant& variant);
101 * Allow or disallow writing of NaN and/or Infinity (as an extension to QJson)
103 void allowSpecialNumbers(bool allow);
106 * Is Nan and/or Infinity allowed?
108 bool specialNumbersAllowed() const;
111 * set output indentation mode as defined in QJson::IndentMode
113 void setIndentMode(IndentMode mode = QJson::IndentNone);
117 * set double precision used while converting Double
118 * \sa QByteArray::number
120 void setDoublePrecision(int precision);
123 * Returns one of the indentation modes defined in QJson::IndentMode
125 IndentMode indentMode() const;
128 Q_DISABLE_COPY(Serializer)
129 class SerializerPrivate;
130 SerializerPrivate* const d;
134 #endif // QJSON_SERIALIZER_H