feat: 自定义 FromBody 绑定——simapi_serialization 按运行时类型反序列化,DTO 免 @Serialization 宏

- SimApiRequestDelegateFactory:无注解参数(FromBody)用 JsonSerializer.Deserialize(typeInfo, body)
  反序列化(免宏、免约束),显式注解参数(Query/Form/Route/Header/Services)委托 soulsoft binder
- 请求体只读一次并缓存到 context.items["SimApi:BodyCache"](body 流不可重读,
  请求日志中间件与 FromBody 共用缓存)
- 验证:/auth/login/admin 的 LoginAdminRequest(无宏)反序列化成功,走到业务密码校验
This commit is contained in:
2026-08-18 00:27:32 +08:00
parent 73f60f6f15
commit e9978ea5e0
3 changed files with 100 additions and 11 deletions
@@ -122,10 +122,11 @@ public class SimApiRequestLogMiddleware <: IMiddleware {
read = context.request.body.read(buffer)
}
let bodyText = sb.toString()
// 重置流位置,供后续业务读取
// 重置流位置,供后续业务读取;同时缓存 body(流可能不可重读)
if (let seekable: Seekable <- context.request.body) {
seekable.seek(SeekPosition.Begin(0))
}
context.items["SimApi:BodyCache"] = bodyText
return truncateBody(bodyText)
} catch (_: Exception) {
return "(读取请求体失败)\n"