1、修改包的图片
2、修改房间的所有进出方式
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
package com.xscm.moduleutil.event;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -10,7 +21,8 @@ import lombok.Data;
|
||||
@Data
|
||||
public class MqttBean {
|
||||
private String room_id;
|
||||
private ListBean list;
|
||||
@JsonAdapter(ListBeanListAdapter.class)
|
||||
private List<ListBean> list;
|
||||
|
||||
public String getRoom_id() {
|
||||
return room_id == null ? "" : room_id;
|
||||
@@ -20,14 +32,58 @@ public class MqttBean {
|
||||
this.room_id = room_id == null ? "" : room_id;
|
||||
}
|
||||
|
||||
public ListBean getList() {
|
||||
public List<ListBean> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(ListBean list) {
|
||||
public void setList(List<ListBean> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
// 自定义TypeAdapter来处理有时是对象有时是数组的情况
|
||||
public static class ListBeanListAdapter extends TypeAdapter<List<ListBean>> {
|
||||
@Override
|
||||
public void write(JsonWriter out, List<ListBean> value) throws IOException {
|
||||
if (value == null) {
|
||||
out.nullValue();
|
||||
return;
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
out.beginArray();
|
||||
for (ListBean item : value) {
|
||||
gson.toJson(item, ListBean.class, out);
|
||||
}
|
||||
out.endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ListBean> read(JsonReader in) throws IOException {
|
||||
List<ListBean> list = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
|
||||
JsonToken token = in.peek();
|
||||
if (token == JsonToken.BEGIN_ARRAY) {
|
||||
// 正常的数组情况
|
||||
in.beginArray();
|
||||
while (in.hasNext()) {
|
||||
ListBean item = gson.fromJson(in, ListBean.class);
|
||||
list.add(item);
|
||||
}
|
||||
in.endArray();
|
||||
} else if (token == JsonToken.BEGIN_OBJECT) {
|
||||
// 单个对象的情况,转换为包含一个元素的列表
|
||||
ListBean item = gson.fromJson(in, ListBean.class);
|
||||
list.add(item);
|
||||
} else if (token == JsonToken.NULL) {
|
||||
in.nextNull();
|
||||
}
|
||||
// 其他情况(如字符串、数字等)直接跳过
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ListBean {
|
||||
private String text;
|
||||
|
||||
Reference in New Issue
Block a user