test: add serialization tests and guidelines for handling null and omitted fields (#583)
This commit is contained in:
parent
3e7ea39bf7
commit
1454229ad9
2 changed files with 52 additions and 0 deletions
|
|
@ -189,6 +189,34 @@ class InitializeTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should serialize InitializeResult without meta - meta must be omitted`() {
|
||||
val result = InitializeResult(
|
||||
protocolVersion = "2025-03-26",
|
||||
capabilities = ServerCapabilities(tools = ServerCapabilities.Tools(listChanged = false)),
|
||||
serverInfo = Implementation(name = "test-server", version = "1.0.0"),
|
||||
)
|
||||
|
||||
verifySerialization(
|
||||
result,
|
||||
McpJson,
|
||||
"""
|
||||
{
|
||||
"protocolVersion": "2025-03-26",
|
||||
"capabilities": {
|
||||
"tools": {
|
||||
"listChanged": false
|
||||
}
|
||||
},
|
||||
"serverInfo": {
|
||||
"name": "test-server",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should deserialize InitializeResult from JSON`() {
|
||||
val json = """
|
||||
|
|
|
|||
|
|
@ -265,6 +265,26 @@ class JsonRpcTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should serialize JSONRPCResponse with EmptyResult - null meta must be omitted`() {
|
||||
val response = JSONRPCResponse(
|
||||
id = RequestId("call-2"),
|
||||
result = EmptyResult(), // meta = null by default
|
||||
)
|
||||
|
||||
verifySerialization(
|
||||
response,
|
||||
McpJson,
|
||||
"""
|
||||
{
|
||||
"id": "call-2",
|
||||
"result": {},
|
||||
"jsonrpc": "2.0"
|
||||
}
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should deserialize JSONRPCResponse with EmptyResult`() {
|
||||
val json = """
|
||||
|
|
|
|||
Loading…
Reference in a new issue