mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 01:20:25 +08:00
使用Object解决泛型问题
This commit is contained in:
@@ -37,12 +37,13 @@ public class ControlResponse {
|
||||
// 信息
|
||||
@JsonProperty("Msg")
|
||||
public String msg;
|
||||
// 数据
|
||||
public class ControlResponseData<E>{
|
||||
public E value;
|
||||
}
|
||||
// // 数据
|
||||
// public class ControlResponseData<E>{
|
||||
// public E value;
|
||||
// }
|
||||
// public ControlResponseData data=new ControlResponseData();
|
||||
@JsonProperty("Data")
|
||||
public ControlResponseData data=new ControlResponseData();
|
||||
public Object data;
|
||||
|
||||
public ControlResponse(){
|
||||
}
|
||||
@@ -51,7 +52,7 @@ public class ControlResponse {
|
||||
this.type=response.type;
|
||||
this.code=response.code;
|
||||
this.msg=response.msg;
|
||||
this.data.value=response.data.value;
|
||||
this.data=response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class ControlResponse {
|
||||
* @return
|
||||
*/
|
||||
public String getString(){
|
||||
return (String) this.data.value;
|
||||
return (String) this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +69,7 @@ public class ControlResponse {
|
||||
*/
|
||||
public void setString(String str){
|
||||
this.type=ControlResponseTypeString;
|
||||
this.data.value=str;
|
||||
this.data=str;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +77,7 @@ public class ControlResponse {
|
||||
* @return
|
||||
*/
|
||||
public ControlResponseMeta getMeta(){
|
||||
return (ControlResponseMeta) this.data.value;
|
||||
return (ControlResponseMeta) this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,7 @@ public class ControlResponse {
|
||||
*/
|
||||
public void setMeta(ControlResponseMeta meta){
|
||||
this.type=ControlResponseTypeMeta;
|
||||
this.data.value=meta;
|
||||
this.data=meta;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +94,7 @@ public class ControlResponse {
|
||||
* @return
|
||||
*/
|
||||
public byte[] getBytes(){
|
||||
return (byte[]) this.data.value;
|
||||
return (byte[]) this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +103,7 @@ public class ControlResponse {
|
||||
*/
|
||||
public void setBytes(byte[] bytes){
|
||||
this.type=ControlResponseTypeBytes;
|
||||
this.data.value=bytes;
|
||||
this.data=bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,11 @@ public class ControlResponseTest {
|
||||
ControlResponse response = new ControlResponse();
|
||||
String jsonString = "{\"Code\": 1, \"Type\": \"string\", \"Msg\": \"bbb\", \"Data\": \"abcd\"}";
|
||||
// Data无法解析
|
||||
response.UnmarshalJSON(jsonString.getBytes());
|
||||
System.out.println(response.UnmarshalJSON(jsonString.getBytes()));
|
||||
System.out.println(response.type);
|
||||
System.out.println(response.msg);
|
||||
System.out.println(response.code);
|
||||
System.out.println(response.data);
|
||||
}catch (Exception ex){
|
||||
LoggerHelper.info(ex.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user