Created the JSONBuilder.java
This commit is contained in:
parent
17dd784e1f
commit
650605c8d7
38
src/main/java/de/gnmyt/mcdash/http/JSONBuilder.java
Normal file
38
src/main/java/de/gnmyt/mcdash/http/JSONBuilder.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.gnmyt.mcdash.http;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class JSONBuilder {
|
||||
|
||||
private final HashMap<String, Object> json = new HashMap<>();
|
||||
private final ResponseController response;
|
||||
|
||||
/**
|
||||
* Constructor of the {@link JSONBuilder}
|
||||
*
|
||||
* @param response The response controller
|
||||
*/
|
||||
public JSONBuilder(ResponseController response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new value to the JSON
|
||||
*
|
||||
* @param key The key of the value
|
||||
* @param value The value you want to add
|
||||
* @return the current {@link JSONBuilder} instance
|
||||
*/
|
||||
public JSONBuilder add(String key, Object value) {
|
||||
json.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the JSON and sends it to the client
|
||||
*/
|
||||
public void finish() {
|
||||
response.json(json);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user