mitreid-connect
静的公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.mitre.util.JsonUtils クラス
org.mitre.util.JsonUtils 連携図
Collaboration graph

静的公開メンバ関数

static JsonElement getAsArray (Set< String > value)
 
static JsonElement getAsArray (Set< String > value, boolean preserveEmpty)
 
static Date getAsDate (JsonObject o, String member)
 
static JWEAlgorithm getAsJweAlgorithm (JsonObject o, String member)
 
static EncryptionMethod getAsJweEncryptionMethod (JsonObject o, String member)
 
static JWSAlgorithm getAsJwsAlgorithm (JsonObject o, String member)
 
static PKCEAlgorithm getAsPkceAlgorithm (JsonObject o, String member)
 
static String getAsString (JsonObject o, String member)
 
static Boolean getAsBoolean (JsonObject o, String member)
 
static Long getAsLong (JsonObject o, String member)
 
static Set< String > getAsStringSet (JsonObject o, String member) throws JsonSyntaxException
 
static List< String > getAsStringList (JsonObject o, String member) throws JsonSyntaxException
 
static List< JWSAlgorithm > getAsJwsAlgorithmList (JsonObject o, String member)
 
static List< JWEAlgorithm > getAsJweAlgorithmList (JsonObject o, String member)
 
static List< EncryptionMethod > getAsEncryptionMethodList (JsonObject o, String member)
 
static Map readMap (JsonReader reader) throws IOException
 
static Set readSet (JsonReader reader) throws IOException
 
static void writeNullSafeArray (JsonWriter writer, Set< String > items) throws IOException
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(JsonUtils.class)
 
static Gson gson = new Gson()
 

詳解

A collection of null-safe converters from common classes and JSON elements, using GSON.

著者
jricher

関数詳解

◆ getAsArray() [1/2]

static JsonElement org.mitre.util.JsonUtils.getAsArray ( Set< String >  value)
inlinestatic

Translate a set of strings to a JSON array, empty array returned as null

引数
value
戻り値
71  {
72  return getAsArray(value, false);
73  }
static JsonElement getAsArray(Set< String > value)
Definition: JsonUtils.java:71

◆ getAsArray() [2/2]

static JsonElement org.mitre.util.JsonUtils.getAsArray ( Set< String >  value,
boolean  preserveEmpty 
)
inlinestatic

Translate a set of strings to a JSON array, optionally preserving the empty array. Otherwise (default) empty array is returned as null.

引数
value
preserveEmpty
戻り値
82  {
83  if (!preserveEmpty && value != null && value.isEmpty()) {
84  // if we're not preserving empty arrays and the value is empty, return null
85  return JsonNull.INSTANCE;
86  } else {
87  return gson.toJsonTree(value, new TypeToken<Set<String>>(){}.getType());
88  }
89  }
static Gson gson
Definition: JsonUtils.java:64

◆ getAsBoolean()

static Boolean org.mitre.util.JsonUtils.getAsBoolean ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a boolean, null if it doesn't exist

177  {
178  if (o.has(member)) {
179  JsonElement e = o.get(member);
180  if (e != null && e.isJsonPrimitive()) {
181  return e.getAsBoolean();
182  } else {
183  return null;
184  }
185  } else {
186  return null;
187  }
188  }

◆ getAsDate()

static Date org.mitre.util.JsonUtils.getAsDate ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member (expressed as integer seconds since epoch) as a Date

94  {
95  if (o.has(member)) {
96  JsonElement e = o.get(member);
97  if (e != null && e.isJsonPrimitive()) {
98  return new Date(e.getAsInt() * 1000L);
99  } else {
100  return null;
101  }
102  } else {
103  return null;
104  }
105  }

◆ getAsEncryptionMethodList()

static List<EncryptionMethod> org.mitre.util.JsonUtils.getAsEncryptionMethodList ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a list of JWS Algorithms, null if it doesn't exist

271  {
272  List<String> strings = getAsStringList(o, member);
273  if (strings != null) {
274  List<EncryptionMethod> algs = new ArrayList<>();
275  for (String alg : strings) {
276  algs.add(EncryptionMethod.parse(alg));
277  }
278  return algs;
279  } else {
280  return null;
281  }
282  }
static List< String > getAsStringList(JsonObject o, String member)
Definition: JsonUtils.java:224

◆ getAsJweAlgorithm()

static JWEAlgorithm org.mitre.util.JsonUtils.getAsJweAlgorithm ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a JWE Algorithm, null if it doesn't exist

110  {
111  String s = getAsString(o, member);
112  if (s != null) {
113  return JWEAlgorithm.parse(s);
114  } else {
115  return null;
116  }
117  }
static String getAsString(JsonObject o, String member)
Definition: JsonUtils.java:161

◆ getAsJweAlgorithmList()

static List<JWEAlgorithm> org.mitre.util.JsonUtils.getAsJweAlgorithmList ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a list of JWS Algorithms, null if it doesn't exist

255  {
256  List<String> strings = getAsStringList(o, member);
257  if (strings != null) {
258  List<JWEAlgorithm> algs = new ArrayList<>();
259  for (String alg : strings) {
260  algs.add(JWEAlgorithm.parse(alg));
261  }
262  return algs;
263  } else {
264  return null;
265  }
266  }
static List< String > getAsStringList(JsonObject o, String member)
Definition: JsonUtils.java:224

◆ getAsJweEncryptionMethod()

static EncryptionMethod org.mitre.util.JsonUtils.getAsJweEncryptionMethod ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a JWE Encryption Method, null if it doesn't exist

122  {
123  String s = getAsString(o, member);
124  if (s != null) {
125  return EncryptionMethod.parse(s);
126  } else {
127  return null;
128  }
129  }
static String getAsString(JsonObject o, String member)
Definition: JsonUtils.java:161

◆ getAsJwsAlgorithm()

static JWSAlgorithm org.mitre.util.JsonUtils.getAsJwsAlgorithm ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a JWS Algorithm, null if it doesn't exist

134  {
135  String s = getAsString(o, member);
136  if (s != null) {
137  return JWSAlgorithm.parse(s);
138  } else {
139  return null;
140  }
141  }
static String getAsString(JsonObject o, String member)
Definition: JsonUtils.java:161

◆ getAsJwsAlgorithmList()

static List<JWSAlgorithm> org.mitre.util.JsonUtils.getAsJwsAlgorithmList ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a list of JWS Algorithms, null if it doesn't exist

239  {
240  List<String> strings = getAsStringList(o, member);
241  if (strings != null) {
242  List<JWSAlgorithm> algs = new ArrayList<>();
243  for (String alg : strings) {
244  algs.add(JWSAlgorithm.parse(alg));
245  }
246  return algs;
247  } else {
248  return null;
249  }
250  }
static List< String > getAsStringList(JsonObject o, String member)
Definition: JsonUtils.java:224

◆ getAsLong()

static Long org.mitre.util.JsonUtils.getAsLong ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a Long, null if it doesn't exist

193  {
194  if (o.has(member)) {
195  JsonElement e = o.get(member);
196  if (e != null && e.isJsonPrimitive()) {
197  return e.getAsLong();
198  } else {
199  return null;
200  }
201  } else {
202  return null;
203  }
204  }

◆ getAsPkceAlgorithm()

static PKCEAlgorithm org.mitre.util.JsonUtils.getAsPkceAlgorithm ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a PKCE Algorithm, null if it doesn't exist

引数
o
member
戻り値
149  {
150  String s = getAsString(o, member);
151  if (s != null) {
152  return PKCEAlgorithm.parse(s);
153  } else {
154  return null;
155  }
156  }
static String getAsString(JsonObject o, String member)
Definition: JsonUtils.java:161

◆ getAsString()

static String org.mitre.util.JsonUtils.getAsString ( JsonObject  o,
String  member 
)
inlinestatic

Gets the value of the given member as a string, null if it doesn't exist

161  {
162  if (o.has(member)) {
163  JsonElement e = o.get(member);
164  if (e != null && e.isJsonPrimitive()) {
165  return e.getAsString();
166  } else {
167  return null;
168  }
169  } else {
170  return null;
171  }
172  }

◆ getAsStringList()

static List<String> org.mitre.util.JsonUtils.getAsStringList ( JsonObject  o,
String  member 
) throws JsonSyntaxException
inlinestatic

Gets the value of the given given member as a set of strings, null if it doesn't exist

224  {
225  if (o.has(member)) {
226  if (o.get(member).isJsonArray()) {
227  return gson.fromJson(o.get(member), new TypeToken<List<String>>(){}.getType());
228  } else {
229  return Lists.newArrayList(o.get(member).getAsString());
230  }
231  } else {
232  return null;
233  }
234  }
static Gson gson
Definition: JsonUtils.java:64

◆ getAsStringSet()

static Set<String> org.mitre.util.JsonUtils.getAsStringSet ( JsonObject  o,
String  member 
) throws JsonSyntaxException
inlinestatic

Gets the value of the given given member as a set of strings, null if it doesn't exist

209  {
210  if (o.has(member)) {
211  if (o.get(member).isJsonArray()) {
212  return gson.fromJson(o.get(member), new TypeToken<Set<String>>(){}.getType());
213  } else {
214  return Sets.newHashSet(o.get(member).getAsString());
215  }
216  } else {
217  return null;
218  }
219  }
static Gson gson
Definition: JsonUtils.java:64

◆ readMap()

static Map org.mitre.util.JsonUtils.readMap ( JsonReader  reader) throws IOException
inlinestatic
284  {
285  Map map = new HashMap<>();
286  reader.beginObject();
287  while(reader.hasNext()) {
288  String name = reader.nextName();
289  Object value = null;
290  switch(reader.peek()) {
291  case STRING:
292  value = reader.nextString();
293  break;
294  case BOOLEAN:
295  value = reader.nextBoolean();
296  break;
297  case NUMBER:
298  value = reader.nextLong();
299  break;
300  default:
301  logger.debug("Found unexpected entry");
302  reader.skipValue();
303  continue;
304  }
305  map.put(name, value);
306  }
307  reader.endObject();
308  return map;
309  }
static final Logger logger
Definition: JsonUtils.java:62

◆ readSet()

static Set org.mitre.util.JsonUtils.readSet ( JsonReader  reader) throws IOException
inlinestatic
311  {
312  Set arraySet = null;
313  reader.beginArray();
314  switch (reader.peek()) {
315  case STRING:
316  arraySet = new HashSet<>();
317  while (reader.hasNext()) {
318  arraySet.add(reader.nextString());
319  }
320  break;
321  case NUMBER:
322  arraySet = new HashSet<>();
323  while (reader.hasNext()) {
324  arraySet.add(reader.nextLong());
325  }
326  break;
327  default:
328  arraySet = new HashSet();
329  break;
330  }
331  reader.endArray();
332  return arraySet;
333  }

◆ writeNullSafeArray()

static void org.mitre.util.JsonUtils.writeNullSafeArray ( JsonWriter  writer,
Set< String >  items 
) throws IOException
inlinestatic
335  {
336  if (items != null) {
337  writer.beginArray();
338  for (String s : items) {
339  writer.value(s);
340  }
341  writer.endArray();
342  } else {
343  writer.nullValue();
344  }
345  }

メンバ詳解

◆ gson

Gson org.mitre.util.JsonUtils.gson = new Gson()
staticprivate

◆ logger

final Logger org.mitre.util.JsonUtils.logger = LoggerFactory.getLogger(JsonUtils.class)
staticprivate

Logger for this class


このクラス詳解は次のファイルから抽出されました: