io.gsonfire.builders.JsonArrayBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gson-fire Show documentation
Show all versions of gson-fire Show documentation
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!
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();
}
}