fastJson
pom导入相关包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.4</version>
</dependency>
代码简单样例
Info info = new Info();
info.setMoveInFlag("1");
info.setDealType("2");
info.setCid("3");
String jsonString = JSON.toJSON(info).toString();
System.out.println(jsonString);
Gson
pom导入相关包
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
代码简单样例
Info info = new Info();
info.setMoveInFlag("1");
info.setDealType("2");
info.setCid("3");
Gson gson = new Gson();
String jsonString = gson.toJson(info);
System.out.println(jsonString);
JackSon
pom导入相关包
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
代码简单样例
Info info = new Info();
info.setMoveInFlag("1");
info.setDealType("2");
info.setCid("3");
ObjectMapper objectMapper = new ObjectMapper();
String jsonString = objectMapper.writeValueAsString(info);
System.out.println(jsonString);