fix: fix json message part cannot be serialized correctly
This commit is contained in:
parent
57177510d5
commit
8b729519b0
1
.idea/modules/MyBot.main.iml
generated
1
.idea/modules/MyBot.main.iml
generated
@ -3,7 +3,6 @@
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$/../../build/generated/sources/annotationProcessor/java/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../build/generated/sources/annotationProcessor/java/main" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../build/generated/sources/annotationProcessor/java/main" isTestSource="false" generated="true" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
1
.idea/modules/mybot-api/MyBot.mybot-api.main.iml
generated
1
.idea/modules/mybot-api/MyBot.mybot-api.main.iml
generated
@ -3,7 +3,6 @@
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$/../../../mybot-api/build/generated/sources/annotationProcessor/java/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../../mybot-api/build/generated/sources/annotationProcessor/java/main" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../../mybot-api/build/generated/sources/annotationProcessor/java/main" isTestSource="false" generated="true" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
@ -14,7 +14,7 @@ allprojects {
|
||||
apply(plugin = "java-library")
|
||||
val groupName by extra("cn.wzpmc")
|
||||
val projectArtifactId by extra("my-bot")
|
||||
val projectVersion by extra("1.0.5")
|
||||
val projectVersion by extra("1.0.6-SNAPSHOT")
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://libraries.minecraft.net")
|
||||
|
@ -21,6 +21,7 @@ public interface JsonMessagePart {
|
||||
* @author wzp
|
||||
* @since 2024/7/31 上午2:40 v0.0.1-dev
|
||||
*/
|
||||
@JSONField(serialize = false, deserialize = false)
|
||||
PartType getPartType();
|
||||
|
||||
@JSONField(name = "type")
|
||||
|
@ -12,6 +12,7 @@ import cn.wzpmc.events.notice.notify.NotifyEvent;
|
||||
import cn.wzpmc.events.request.RequestEvent;
|
||||
import cn.wzpmc.message.StringMessage;
|
||||
import cn.wzpmc.message.json.JsonMessage;
|
||||
import cn.wzpmc.message.json.JsonMessagePart;
|
||||
import cn.wzpmc.user.Friend;
|
||||
import cn.wzpmc.user.IBot;
|
||||
import cn.wzpmc.user.IUser;
|
||||
@ -20,10 +21,7 @@ import cn.wzpmc.utils.json.action.ActionReader;
|
||||
import cn.wzpmc.utils.json.action.ActionWriter;
|
||||
import cn.wzpmc.utils.json.event.*;
|
||||
import cn.wzpmc.utils.json.honor.HonorWriter;
|
||||
import cn.wzpmc.utils.json.message.JsonMessageReader;
|
||||
import cn.wzpmc.utils.json.message.JsonMessageWriter;
|
||||
import cn.wzpmc.utils.json.message.StringMessageReader;
|
||||
import cn.wzpmc.utils.json.message.StringMessageWriter;
|
||||
import cn.wzpmc.utils.json.message.*;
|
||||
import cn.wzpmc.utils.json.user.FriendUserReader;
|
||||
import cn.wzpmc.utils.json.user.GroupUserReader;
|
||||
import cn.wzpmc.utils.json.user.IBotReader;
|
||||
@ -49,6 +47,7 @@ public class JsonUtils {
|
||||
JSON.register(Actions.class, new ActionWriter());
|
||||
JSON.register(HonorType.class, new HonorWriter());
|
||||
JSON.register(StringMessage.class, new StringMessageWriter());
|
||||
JSON.register(JsonMessagePart.class, new JsonMessagePartWriter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cn.wzpmc.utils.json.message;
|
||||
|
||||
import cn.wzpmc.message.json.JsonMessagePart;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author wzp
|
||||
* @since 2025/2/1 04:19
|
||||
* @version 1.0.5
|
||||
**/
|
||||
public class JsonMessagePartWriter implements ObjectWriter<JsonMessagePart> {
|
||||
@Override
|
||||
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
|
||||
if (object instanceof JsonMessagePart) {
|
||||
System.out.println(object);
|
||||
JSONObject from = JSONObject.from(object);
|
||||
from.put("type", ((JsonMessagePart) object).getStringPartType());
|
||||
jsonWriter.write(from);
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ public class JsonMessageWriter implements ObjectWriter<JsonMessage> {
|
||||
ObjectWriter<?> objectWriter = creator.createObjectWriter(StringMessage.class);
|
||||
objectWriter.write(jsonWriter, messagePart);
|
||||
} else {
|
||||
jsonWriter.writeAny(messagePart);
|
||||
new JsonMessagePartWriter().write(jsonWriter, messagePart);
|
||||
}
|
||||
if (i != size - 1) {
|
||||
jsonWriter.writeComma();
|
||||
|
Loading…
x
Reference in New Issue
Block a user