net.vvakame.util.jsonpullparser.builder.JsonModelBuilder Maven / Gradle / Ivy
package net.vvakame.util.jsonpullparser.builder;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* JSON model builder.
* @author vvakame
* @param
*/
public abstract class JsonModelBuilder {
protected Class baseClass;
protected boolean treatUnknownKeyAsError;
protected Map> map =
new LinkedHashMap>();
/**
* the constructor.
* @param baseClass
* @param treatUnknownKeyAsError
* @category constructor
*/
public JsonModelBuilder(Class baseClass, boolean treatUnknownKeyAsError) {
this.baseClass = baseClass;
this.treatUnknownKeyAsError = treatUnknownKeyAsError;
}
/**
* Attaches property builder for the all types.
* @return this
* @author vvakame
*/
public abstract JsonModelBuilder addAll();
/**
* Attaches property builder for the given types.
* @param creators
* @return this
* @author vvakame
*/
public JsonModelBuilder add(JsonPropertyBuilderCreator... creators) {
for (JsonPropertyBuilderCreator creator : creators) {
addSub(creator. get());
}
return this;
}
protected void addSub(JsonPropertyBuilder builder) {
map.put(builder.name, builder);
}
/**
* Detaches property builder for the given types.
* @param creators
* @return this
* @author vvakame
*/
public JsonModelBuilder rm(JsonPropertyBuilderCreator... creators) {
for (JsonPropertyBuilderCreator creator : creators) {
rmSub(creator. get());
}
return this;
}
protected void rmSub(JsonPropertyBuilder builder) {
map.remove(builder.name);
}
/**
* Detaches property builder for the given names.
* @param names
* @return this
* @author vvakame
*/
public JsonModelBuilder rm(String... names) {
for (String name : names) {
rmSub(name);
}
return this;
}
protected void rmSub(String name) {
map.remove(name);
}
/**
* Sets if the exception should be thrown upon deserializing unknown keys.
* @param treatUnknownKeyAsError
* @return this
* @author vvakame
*/
public JsonModelBuilder treatUnknownKeyAsError(boolean treatUnknownKeyAsError) {
this.treatUnknownKeyAsError = treatUnknownKeyAsError;
return this;
}
/**
* Fixiates the current state for coding.
* @return A JsonModelCoder instance for the actual coding.
* @author vvakame
*/
public abstract JsonModelCoder fix();
}