我有一个模板对象类型 ExternalActionReqBean 有一个对象,可以通过指示操作字段设置任何类
让我们说,如果 action="FROZEN" , ExternalActionReqBean->payload 将使用 ExternalActionFrozenReqBean 类类型,如果 action="UNFROZEN" ExternalActionUnFrozenReqBean 类类型将被使用。
如果有效载荷如下所示,实现这一目标的最佳实践是什么?
{"txnID":"txn","action":"FROZEN","resource":"PNSENDER","payload":{"msisdn_list":["xxxx","xxx","xxx"]}}
ExternalActionReqBean externalActionReqBean = GSON.fromJson(payload, ExternalActionReqBean.class);
if("FROZEN".equals(externalActionReqBean.getAction())){
// externalActionFrozenReqBean = GSON.fromJson(externalActionReqBean.getPayload(),ExternalActionFrozenReqBean.class);
}
@Data
@AllArgsConstructor
public class ExternalActionReqBean {
private String txnID;
private String action;
private String resource;
private Object payload;
}
@Data
public class ExternalActionFrozenReqBean {
private List<String> msisdn_list;
}
@Data
public class ExternalActionUnFrozenReqBean {
private String result;
}
开满天机
相关分类