com.litongjava.tio.utils.json.GsonJson Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-utils Show documentation
Show all versions of tio-utils Show documentation
t-io is a aio framework for java
package com.litongjava.tio.utils.json;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
public class GsonJson extends Json {
private Gson gson = new Gson();
@Override
public String toJson(Object object) {
return gson.toJson(object);
}
@Override
public byte[] toJsonBytes(Object object) {
return gson.toJson(object).getBytes(StandardCharsets.UTF_8);
}
@Override
public T parse(String jsonString, Class type) {
return gson.fromJson(jsonString, type);
}
@Override
public Map, ?> parseToMap(String json) {
Type mapType = new TypeToken