redis.clients.jedis.json.JsonBuilderFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis_preview Show documentation
Show all versions of jedis_preview Show documentation
Jedis is a blazingly small and sane Redis java client.
The newest version!
package redis.clients.jedis.json;
import static redis.clients.jedis.BuilderFactory.STRING;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import redis.clients.jedis.Builder;
import redis.clients.jedis.BuilderFactory;
import redis.clients.jedis.exceptions.JedisException;
public final class JsonBuilderFactory {
public static final Builder> JSON_TYPE = new Builder>() {
@Override
public Class> build(Object data) {
if (data == null) return null;
String str = STRING.build(data);
switch (str) {
case "null":
return null;
case "boolean":
return boolean.class;
case "integer":
return int.class;
case "number":
return float.class;
case "string":
return String.class;
case "object":
return Object.class;
case "array":
return List.class;
default:
throw new JedisException("Unknown type: " + str);
}
}
@Override
public String toString() {
return "Class>";
}
};
public static final Builder>> JSON_TYPE_LIST = new Builder>>() {
@Override
public List> build(Object data) {
List