Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
94c3e2f5
Commit
94c3e2f5
authored
Feb 04, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix json parser polymorphic support
parent
2c9d38df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
+25
-15
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
...-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
+1
-3
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/DTO.kt
...-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/DTO.kt
+24
-12
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
View file @
94c3e2f5
...
@@ -87,9 +87,7 @@ abstract class Session internal constructor(
...
@@ -87,9 +87,7 @@ abstract class Session internal constructor(
*
*
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
*/
*/
class
TempSession
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
{
class
TempSession
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
}
/**
/**
* 任何[TempSession]认证后转化为一个[AuthedSession]
* 任何[TempSession]认证后转化为一个[AuthedSession]
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/DTO.kt
View file @
94c3e2f5
...
@@ -2,19 +2,10 @@ package net.mamoe.mirai.api.http.dto
...
@@ -2,19 +2,10 @@ package net.mamoe.mirai.api.http.dto
import
kotlinx.serialization.*
import
kotlinx.serialization.*
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.modules.SerializersModule
interface
DTO
interface
DTO
object
MiraiJson
{
// val json = Json(context = SerializersModule {
// polymorphic(MessagePacketDTO.serializer()) {
// GroupMessagePacketDTO::class with GroupMessagePacketDTO.serializer()
// FriendMessagePacketDTO::class with FriendMessagePacketDTO.serializer()
// }
// })
val
json
=
Json
}
// 解析失败时直接返回null,由路由判断响应400状态
// 解析失败时直接返回null,由路由判断响应400状态
@UseExperimental
(
ImplicitReflectionSerializer
::
class
)
@UseExperimental
(
ImplicitReflectionSerializer
::
class
)
inline
fun
<
reified
T
:
Any
>
String
.
jsonParseOrNull
(
inline
fun
<
reified
T
:
Any
>
String
.
jsonParseOrNull
(
...
@@ -32,7 +23,6 @@ inline fun <reified T : Any> T.toJson(
...
@@ -32,7 +23,6 @@ inline fun <reified T : Any> T.toJson(
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
// 序列化列表时,stringify需要使用的泛型是T,而非List<T>
// 序列化列表时,stringify需要使用的泛型是T,而非List<T>
// 因为使用的stringify的stringify(objs: List<T>)重载
// 因为使用的stringify的stringify(objs: List<T>)重载
@UseExperimental
(
ImplicitReflectionSerializer
::
class
,
UnstableDefault
::
class
)
@UseExperimental
(
ImplicitReflectionSerializer
::
class
,
UnstableDefault
::
class
)
...
@@ -40,3 +30,25 @@ inline fun <reified T : Any> List<T>.toJson(
...
@@ -40,3 +30,25 @@ inline fun <reified T : Any> List<T>.toJson(
serializer
:
SerializationStrategy
<
List
<
T
>>?
=
null
serializer
:
SerializationStrategy
<
List
<
T
>>?
=
null
):
String
=
if
(
serializer
==
null
)
MiraiJson
.
json
.
stringify
(
this
)
):
String
=
if
(
serializer
==
null
)
MiraiJson
.
json
.
stringify
(
this
)
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
/**
* Json解析规则,需要注册支持的多态的类
*/
object
MiraiJson
{
val
json
=
Json
(
context
=
SerializersModule
{
polymorphic
(
MessagePacketDTO
.
serializer
())
{
GroupMessagePacketDTO
::
class
with
GroupMessagePacketDTO
.
serializer
()
FriendMessagePacketDTO
::
class
with
FriendMessagePacketDTO
.
serializer
()
UnKnownMessagePacketDTO
::
class
with
UnKnownMessagePacketDTO
.
serializer
()
}
polymorphic
(
MessageDTO
.
serializer
())
{
AtDTO
::
class
with
AtDTO
.
serializer
()
FaceDTO
::
class
with
FaceDTO
.
serializer
()
PlainDTO
::
class
with
PlainDTO
.
serializer
()
ImageDTO
::
class
with
ImageDTO
.
serializer
()
XmlDTO
::
class
with
XmlDTO
.
serializer
()
UnknownMessageDTO
::
class
with
UnknownMessageDTO
.
serializer
()
}
})
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment