michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.util; michael@0: michael@0: import java.util.UUID; michael@0: michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: michael@0: public final class JSONUtils { michael@0: private JSONUtils() {} michael@0: michael@0: public static UUID getUUID(String name, JSONObject json) { michael@0: String uuid = json.optString(name, null); michael@0: return (uuid != null) ? UUID.fromString(uuid) : null; michael@0: } michael@0: michael@0: public static void putUUID(String name, UUID uuid, JSONObject json) { michael@0: String uuidString = uuid.toString(); michael@0: try { michael@0: json.put(name, uuidString); michael@0: } catch (JSONException e) { michael@0: throw new IllegalArgumentException(name + "=" + uuidString, e); michael@0: } michael@0: } michael@0: }