我正在使用 Jackson 将 POJO 序列化为 JSON。但是,我得到的 JSON 是:
{
"@type": "com.company.services.alert.dto.JungleEventDTO",
"company": "xyz",
"enabled": true,
"support": false,
..
}
我不想向客户公开我的类(class)名称。
我该怎么做?
最佳答案
您可以使用@JsonTypeId 或@JsonTypeName 或@JsonTypeInfo 进行类型处理。
引用自https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations
@JsonTypeId: property annotation used to indicate that the property value should be used as the Type Id for object, instead of using class name or external type name.
另请参阅 How can I prevent Jackson from serializing a polymorphic type's annotation property?
关于java - 如何在使用 Jackson 将对象序列化为 JSON 时避免 @type 中的类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34395789/