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

io.gsonfire.builders.JsonArrayBuilder Maven / Gradle / Ivy

Go to download

A java library that adds some very useful features to Gson, like Date serializing to unix timestamp or RFC3339, method (getter) serialization, pre and post processors and many more. Check out the documentation to learn how to use it!

There is a newer version: 1.9.0
Show newest version
package io.gsonfire.builders;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import io.gsonfire.util.JsonUtils;

/**
 * Created by julio on 8/18/16.
 */
public final class JsonArrayBuilder implements JsonElementBuilder {

    private final JsonArray array = new JsonArray();

    public JsonArrayBuilder() {

    }

    public JsonArrayBuilder add(JsonElement element) {
        array.add(element);
        return this;
    }

    public JsonArrayBuilder add(JsonElementBuilder builder) {
        array.add(builder.build());
        return this;
    }

    public JsonArrayBuilder add(Boolean bool) {
        array.add(bool);
        return this;
    }

    public JsonArrayBuilder add(Character character) {
        array.add(character);
        return this;
    }

    public JsonArrayBuilder add(Number number) {
        array.add(number);
        return this;
    }

    public JsonArrayBuilder add(String string) {
        array.add(string);
        return this;
    }

    public JsonArrayBuilder addAll(JsonArray jsonArray) {
        array.addAll(jsonArray);
        return this;
    }

    @Override
    public JsonArray build() {
        return JsonUtils.deepCopy(array).getAsJsonArray();
    }

    public static JsonArrayBuilder start() {
        return new JsonArrayBuilder();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy