gson

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>
posted @ 2021-08-18 15:07  zJanly  阅读(184)  评论(0编辑  收藏  举报