import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
public class A {
@Expose
private int id = 1;
@Expose
private String jsonrpc = "2.0";
public static String f(Object... a){
return gson.toJson(a);
}
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
public static void main(String[] args) {
A a = new A();
System.out.println(f(1, "afdasf", new int[]{1,2}));
}
}
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>