Redkale 2.6.0 结束
This commit is contained in:
57
src/test/java/org/redkale/test/convert/DyncJsonTest.java
Normal file
57
src/test/java/org/redkale/test/convert/DyncJsonTest.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class DyncJsonTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
new DyncJsonTest().run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
SimpleDyncBean bean = new SimpleDyncBean();
|
||||
bean.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean));
|
||||
|
||||
SimpleDyncBean2 bean2 = new SimpleDyncBean2();
|
||||
bean2.name = "haha";
|
||||
|
||||
System.out.println(JsonConvert.root().convertTo(bean2));
|
||||
SimpleDyncBean3 bean3 = new SimpleDyncBean3();
|
||||
bean3.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean3));
|
||||
}
|
||||
|
||||
public static class SimpleDyncBean {
|
||||
|
||||
public String name;
|
||||
|
||||
public List<SimpleDyncBean> beans;
|
||||
}
|
||||
|
||||
public static class SimpleDyncBean2 {
|
||||
|
||||
public String name;
|
||||
|
||||
public SimpleDyncBean2 bean2;
|
||||
}
|
||||
|
||||
public static class SimpleDyncBean3 {
|
||||
|
||||
public String name;
|
||||
|
||||
public Map<String, SimpleDyncBean3> beanmap;
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,10 @@ public class ChatService implements Service {
|
||||
public void chatMessage(ChatMessage message) {
|
||||
wsnode.broadcastMessage(message);
|
||||
}
|
||||
|
||||
@Comment("其他操作")
|
||||
public void other(int roomid, String name) {
|
||||
System.out.println("其他操作: roomid: " + roomid + ", name: " + name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -91,4 +91,21 @@ public class ChatWebSocket extends WebSocket<Integer, Object> {
|
||||
service.joinRoom(getUserid(), roomid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器WebSocket请求:
|
||||
* <pre>
|
||||
* websocket.send(JSON.stringify({
|
||||
* roomid: 10212
|
||||
* name: "haha"
|
||||
* }));
|
||||
* </pre>
|
||||
*
|
||||
* @param roomid 参数1
|
||||
* @param name 参数2
|
||||
*/
|
||||
@RestOnMessage(name = "*") //*为特殊值表示参数中不包含方法名
|
||||
public void other(int roomid, String name) {
|
||||
service.other(roomid, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
public _DyncChatWebSocketServlet() {
|
||||
super();
|
||||
this.messageTextType = _DyncChatWebSocketMessage.class;
|
||||
this.messageRestType = _DyncChatWebSocketMessage.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,12 +52,48 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
}
|
||||
}
|
||||
|
||||
public static class _DyncChatWebSocketMessage {
|
||||
public static class _DyncChatWebSocketMessage implements WebSocketParam, Runnable {
|
||||
|
||||
public _DyncChatWebSocketMessage_sendmessagee_00 sendmessage;
|
||||
|
||||
public _DyncChatWebSocketMessage_joinroom_01 joinroom;
|
||||
|
||||
@ConvertDisabled
|
||||
public _DyncChatWebSocket _redkale_websocket;
|
||||
|
||||
public int roomid;
|
||||
|
||||
public String name;
|
||||
|
||||
@Override
|
||||
public String[] getNames() {
|
||||
return new String[]{"roomid", "name"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(String name) {
|
||||
if ("roomid".equals(name)) return (T) (Integer) roomid;
|
||||
if ("name".equals(name)) return (T) (String) name;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Annotation[] getAnnotations() {
|
||||
Annotation[] annotations = _redkale_annotations.get("org/redkale/test/wsdync/_DyncChatWebSocketServlet$_DyncChatWebSocketMessage");
|
||||
if (annotations == null) return new Annotation[0];
|
||||
return Arrays.copyOf(annotations, annotations.length);
|
||||
}
|
||||
|
||||
public void execute(_DyncChatWebSocket websocket) {
|
||||
this._redkale_websocket = websocket;
|
||||
websocket.preOnMessage("*", this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
_redkale_websocket.other(this.roomid, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
@@ -163,6 +199,7 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
message.joinroom.execute(websocket);
|
||||
return;
|
||||
}
|
||||
message.execute(websocket);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user