All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.maven.docker.util.JsonFactory Maven / Gradle / Ivy

There is a newer version: 0.45.0
Show newest version
package io.fabric8.maven.docker.util;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.util.List;
import java.util.Map;

public class JsonFactory {
    private static final Gson GSON = new Gson();

    private JsonFactory() {
        // Empty Constructor
    }

    public static JsonObject newJsonObject(String json) {
        return GSON.fromJson(json, JsonObject.class);
    }

    public static JsonArray newJsonArray(String json) {
        return GSON.fromJson(json, JsonArray.class);
    }

    public static JsonArray newJsonArray(List list) {
        final JsonArray jsonArray = new JsonArray();

        for(String element : list)
        {
            jsonArray.add(element);
        }

        return jsonArray;
    }

    public static JsonObject newJsonObject(Map map) {
        final JsonObject jsonObject = new JsonObject();

        for (Map.Entry entry : map.entrySet()) {
            jsonObject.addProperty(entry.getKey(), entry.getValue());
        }

        return jsonObject;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy