AWS SDK for C++  0.14.3
AWS SDK for C++
JsonSerializer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <aws/core/Core_EXPORTS.h>
19 
20 #include <aws/core/utils/Array.h>
24 
25 #include <utility>
26 
27 namespace Aws
28 {
29  namespace Utils
30  {
31  namespace Json
32  {
37  {
38  public:
42  JsonValue();
43 
48  JsonValue(const Aws::String& value);
49 
53  JsonValue(Aws::IStream& istream);
54 
58  JsonValue(const JsonValue& value);
59 
63  JsonValue(JsonValue&& value);
64 
65  ~JsonValue();
66 
67  JsonValue& operator=(const JsonValue& other);
68 
69  JsonValue& operator=(JsonValue&& other);
70 
71  bool operator!=(const JsonValue& other)
72  {
73  return m_value != other.m_value;
74  }
75 
76  bool operator==(const JsonValue& other)
77  {
78  return m_value == other.m_value;
79  }
80 
84  Aws::String GetString(const Aws::String& key) const;
85  Aws::String GetString(const char* key) const;
86 
90  JsonValue& WithString(const Aws::String& key, const Aws::String& value);
91  JsonValue& WithString(const char* key, const Aws::String& value);
92 
96  JsonValue& AsString(const Aws::String& value);
97 
101  Aws::String AsString() const;
102 
106  bool GetBool(const Aws::String& key) const;
107  bool GetBool(const char* key) const;
108 
112  JsonValue& WithBool(const Aws::String& key, bool value);
113  JsonValue& WithBool(const char* key, bool value);
114 
118  JsonValue& AsBool(bool value);
119 
123  bool AsBool() const;
124 
128  int GetInteger(const Aws::String& key) const;
129  int GetInteger(const char* key) const;
130 
134  JsonValue& WithInteger(const Aws::String& key, int value);
135  JsonValue& WithInteger(const char* key, int value);
136 
140  JsonValue& AsInteger(int value);
141 
145  int AsInteger() const;
146 
150  long long GetInt64(const Aws::String& key) const;
151  long long GetInt64(const char* key) const;
152 
156  JsonValue& WithInt64(const Aws::String& key, long long value);
157  JsonValue& WithInt64(const char* key, long long value);
158 
162  JsonValue& AsInt64(long long value);
163 
167  long long AsInt64() const;
168 
172  double GetDouble(const Aws::String& key) const;
173  double GetDouble(const char* key) const;
174 
178  JsonValue& WithDouble(const Aws::String& key, double value);
179  JsonValue& WithDouble(const char* key, double value);
180 
184  JsonValue& AsDouble(double value);
185 
189  double AsDouble() const;
190 
194  Array<JsonValue> GetArray(const Aws::String& key) const;
195  Array<JsonValue> GetArray(const char* key) const;
196 
200  JsonValue& WithArray(const Aws::String& key, const Array<Aws::String>& array);
201  JsonValue& WithArray(const char* key, const Array<Aws::String>& array);
202 
208  JsonValue& WithArray(const Aws::String& key, Array<Aws::String>&& array);
209 
213  JsonValue& WithArray(const Aws::String& key, const Array<JsonValue>& array);
214 
220  JsonValue& WithArray(const Aws::String& key, Array<JsonValue>&& array);
221 
225  JsonValue& AsArray(const Array<JsonValue>& array);
226 
230  JsonValue& AsArray(Array<JsonValue>&& array);
231 
235  Array<JsonValue> AsArray() const;
236 
240  JsonValue GetObject(const char* key) const;
241  JsonValue GetObject(const Aws::String& key) const;
242 
246  JsonValue& WithObject(const Aws::String& key, const JsonValue& value);
247  JsonValue& WithObject(const char* key, const JsonValue& value);
248 
252  JsonValue& WithObject(const Aws::String& key, const JsonValue&& value);
253  JsonValue& WithObject(const char* key, const JsonValue&& value);
254 
258  JsonValue& AsObject(const JsonValue& value);
259 
263  JsonValue& AsObject(JsonValue&& value);
264 
268  JsonValue AsObject() const;
269 
274  Aws::Map<Aws::String, JsonValue> GetAllObjects() const;
275 
281  bool ValueExists(const char* key) const;
282  bool ValueExists(const Aws::String& key) const;
283 
288  Aws::String WriteCompact(bool treatAsObject = true) const;
289 
293  void WriteCompact(Aws::OStream& ostream, bool treatAsObject = true) const;
294 
299  Aws::String WriteReadable(bool treatAsObject = true) const;
300 
304  void WriteReadable(Aws::OStream& ostream, bool treatAsObject = true) const;
305 
310  inline bool WasParseSuccessful() const
311  {
312  return m_wasParseSuccessful;
313  }
314 
318  inline const Aws::String& GetErrorMessage() const
319  {
320  return m_errorMessage;
321  }
325  void AppendValue(const JsonValue& value);
326 
327  bool IsObject() const;
328  bool IsBool() const;
329  bool IsString() const;
330  bool IsIntegerType() const;
331  bool IsFloatingPointType() const;
332  bool IsListType() const;
333 
335 
336  private:
338 
339  JsonValue& operator=(Aws::External::Json::Value& other);
340 
341  mutable Aws::External::Json::Value m_value;
342  bool m_wasParseSuccessful;
343  Aws::String m_errorMessage;
344  };
345 
346  } // namespace Json
347  } // namespace Utils
348 } // namespace Aws
349 
Represents a JSON value.
Definition: json.h:511
const Aws::String & GetErrorMessage() const
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:28
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:30
bool operator==(const JsonValue &other)
bool operator!=(const JsonValue &other)
std::basic_ostream< char, std::char_traits< char > > OStream
Definition: AWSStreamFwd.h:31
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::External::Json::Value & ModifyRawValue()
#define AWS_CORE_API
Definition: Core_EXPORTS.h:35
JSON (JavaScript Object Notation).