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