548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch/*
81db14effa88a707fad039b67f41454a99c5115bJon Branch * The contents of this file are subject to the terms of the Common Development and
81db14effa88a707fad039b67f41454a99c5115bJon Branch * Distribution License (the License). You may not use this file except in compliance with the
81db14effa88a707fad039b67f41454a99c5115bJon Branch * License.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch *
81db14effa88a707fad039b67f41454a99c5115bJon Branch * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
81db14effa88a707fad039b67f41454a99c5115bJon Branch * specific language governing permission and limitations under the License.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch *
81db14effa88a707fad039b67f41454a99c5115bJon Branch * When distributing Covered Software, include this CDDL Header Notice in each file and include
81db14effa88a707fad039b67f41454a99c5115bJon Branch * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
81db14effa88a707fad039b67f41454a99c5115bJon Branch * Header, with the fields enclosed by brackets [] replaced by your own identifying
81db14effa88a707fad039b67f41454a99c5115bJon Branch * information: "Portions copyright [year] [name of copyright owner]".
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch *
81db14effa88a707fad039b67f41454a99c5115bJon Branch * Copyright 2015 ForgeRock AS.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch */
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchimport static org.forgerock.json.JsonValue.*;
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchimport org.forgerock.json.JsonValue
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchimport org.forgerock.http.util.Json;
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchpublic class JsonValueUtil {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch public static JsonValue fromEntries(Map.Entry<String,Object>[] entries) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch JsonValue json = json(object());
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch for (Map.Entry<String,Object> entry : entries) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch if (entry.getKey() != null && entry.getValue() != null) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch json.add(entry.getKey(), entry.getValue());
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch return json;
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch public static JsonValue fromJsonString(String string) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch return string != null && string.length() > 0 ? json(Json.readJson(string)) : null;
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch public static Boolean booleanFromString(String string) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch try {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch return Boolean.valueOf(string);
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch } catch (Exception e) {
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch return Boolean.FALSE;
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch }
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch}