Code example for JsonObject

Methods: getAsJsonObjectisJsonObject

0
        return value;
    } 
 
    public String extractMonthDayFormatParameter(final JsonObject element) {
        String value = null;
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
 
            final String monthDayFormatParameter = "monthDayFormat";
            if (object.has(monthDayFormatParameter) && object.get(monthDayFormatParameter).isJsonPrimitive()) {
                final JsonPrimitive primitive = object.get(monthDayFormatParameter).getAsJsonPrimitive();
                value = primitive.getAsString();
            } 
        } 
        return value;
    } 
 
    public Locale extractLocaleParameter(final JsonObject element) {
        Locale clientApplicationLocale = null;
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
 
            String locale = null;
            final String localeParameter = "locale";
            if (object.has(localeParameter) && object.get(localeParameter).isJsonPrimitive()) {
                final JsonPrimitive primitive = object.get(localeParameter).getAsJsonPrimitive();
                locale = primitive.getAsString();
                clientApplicationLocale = localeFromString(locale);
            } 
        } 
        return clientApplicationLocale;
    } 
 
    public String[] extractArrayNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
        String[] arrayValue = null;
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
            if (object.has(parameterName)) {
                parametersPassedInRequest.add(parameterName);
                JsonArray array = object.get(parameterName).getAsJsonArray();
                arrayValue = new String[array.size()];
                for (int i = 0; i < array.size(); i++) {
                    arrayValue[i] = array.get(i).getAsString();
                } 
            } 
        } 
        return arrayValue;
    } 
 
    public JsonArray extractJsonArrayNamed(final String parameterName, final JsonElement element) {
        JsonArray jsonArray = null;
 
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
            if (object.has(parameterName)) {
                jsonArray = object.get(parameterName).getAsJsonArray();
            } 
        } 
 
        return jsonArray;
    } 
 
    /** 
     * Used with the local date is in array format 
     */ 
    public LocalDate extractLocalDateAsArrayNamed(final String parameterName, final JsonElement element,
            final Set<String> parametersPassedInCommand) {
        LocalDate value = null;
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
 
            if (object.has(parameterName) && object.get(parameterName).isJsonArray()) {
 
                parametersPassedInCommand.add(parameterName);
 
                final JsonArray dateArray = object.get(parameterName).getAsJsonArray();
 
                Integer year = dateArray.get(0).getAsInt();
                Integer month = dateArray.get(1).getAsInt();
                Integer day = dateArray.get(2).getAsInt();
 
                value = new LocalDate().withYearOfEra(year).withMonthOfYear(month).withDayOfMonth(day);
            } 
 
        } 
        return value;
    } 
 
    public MonthDay extractMonthDayNamed(final String parameterName, final JsonElement element) {
 
        MonthDay value = null;
 
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
 
            final String monthDayFormat = extractMonthDayFormatParameter(object);
            final Locale clientApplicationLocale = extractLocaleParameter(object);
            value = extractMonthDayNamed(parameterName, object, monthDayFormat, clientApplicationLocale);
        } 
        return value;
    } 
 
    public MonthDay extractMonthDayNamed(final String parameterName, final JsonObject element, final String dateFormat,
            final Locale clientApplicationLocale) {
        MonthDay value = null;
        if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
 
            if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {
 
                final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
                final String valueAsString = primitive.getAsString();
Contextual code suggestions in your IDE  Get Codota for Java