【问题标题】:how to change the case of properties with MassTransit如何使用 MassTransit 更改属性的大小写
【发布时间】:2021-09-05 09:57:00
【问题描述】:

如何将属性的格式从 camelCase 更改为 PascalCase。

有没有标准化的格式化方式?一些中间件?我在文档中没有找到任何内容。

还有一个问题。为什么masstransit的json转换器会把十进制转成字符串?

示例: 我的班级:

public class Block
{
    public string Name { get; set; }
    public int Age { get; set; }
    public int AccountValue { get; set; }
}

当前生成的消息:

{
  "name": 3,
  "age": 34,
  "accountValue": "3430.64"
}

预期消息:

{
  "Name": 3,
  "Age": 34,
  "AccountValue": 3430.64
}

感谢您的帮助

【问题讨论】:

    标签: c# .net asp.net-core .net-core masstransit


    【解决方案1】:

    要更改 JSON 序列化程序设置,您可以调用:

    cfg.ConfigureJsonSerializer(x => ...)

    配置总线时。

    MassTransit 将 decimal 转换为字符串,因为 decimal 类型比 JSON 浮点类型更精确。如果您希望它不是字符串,请使用双精度而不是小数。

    对于相关的 cmets,look at this answer 关于为什么不应该将小数作为 JSON 浮点数传递。

    【讨论】:

    • 感谢@Chris Patterson。你帮了我很多
    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 2018-01-19
    • 2018-01-10
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多