1.增加guava-18.0.jar,用于gson将json转为泛型list

2.调整欺骗ip下发的结构,外层加一层[]
This commit is contained in:
chenjinsong
2018-04-09 16:24:17 +08:00
parent 116087c068
commit fdf20225aa
5 changed files with 32 additions and 5 deletions

View File

@@ -33,6 +33,7 @@ public class DnsIpCfgService extends CrudService<DnsIpCfgDao, DnsIpCfg>{
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
//组织要发送的json
List<ToMaatDnsIpBean> toMaatData = new ArrayList<ToMaatDnsIpBean>();
ToMaatDnsIpBean toMaatBean = new ToMaatDnsIpBean();
List<MaatDnsIpCfg> ipCfgList = new ArrayList<MaatDnsIpCfg>();
MaatDnsIpCfg ipCfg = new MaatDnsIpCfg();
@@ -47,7 +48,9 @@ public class DnsIpCfgService extends CrudService<DnsIpCfgDao, DnsIpCfg>{
toMaatBean.setIsValid(1);
toMaatBean.setRequestId(dnsIpCfg.getRequest().getId());
String sendJson = gson.toJson(toMaatBean);
toMaatData.add(toMaatBean);
String sendJson = gson.toJson(toMaatData);
logger.info("准备下发配置:" + sendJson);
//下发配置、接收结果

View File

@@ -1,10 +1,12 @@
package com.nis.web.test;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.nis.domain.configuration.DnsIpCfg;
import com.nis.domain.maat.DnsIpRecvData;
import com.nis.domain.maat.FromMaatBean;
@@ -19,8 +21,9 @@ public class DnsIpTest {
*/
public static String examine(String recv) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
ToMaatDnsIpBean fromJson = gson.fromJson(recv, ToMaatDnsIpBean.class);
List<MaatDnsIpCfg> serviceCfg = fromJson.getServiceCfg();
Type type = new TypeToken<List<ToMaatDnsIpBean>>(){}.getType();
List<ToMaatDnsIpBean> fromJson = gson.fromJson(recv, type);
List<MaatDnsIpCfg> serviceCfg = fromJson.get(0).getServiceCfg();
FromMaatBean fBean = new FromMaatBean();
List<DnsIpRecvData> data = new ArrayList<DnsIpRecvData>();