DTO 和实体映射

DTO and Entities mapping

我正在构建一个 Spring Rest 应用程序,我需要 DTO 方面的帮助并将结果解析到端点

我不想return这个json的“方法”,我只需要“id”、“name”、“description”、“mash_temp”-所以它应该是这样的:

{
  "id": 1,
  "name": "Ella - IPA Is Dead",
  "description": "2015 IPA is Dead Series. Supremely floral, this hugely under-rated hop is related to Galaxy and was first cultivated in the Australian state of Victoria. Initially given the same name as a certain Eurolager, their lawyers got involved and the St- prefix was dropped. Ella displays subtle notes of spice, but is fundamentally a truly floral bouquet, redolent of the Southern Hemisphere.",
  "mash_temp": [
   {
      "temp": {
         "value": 65
         }
      }
  ]
}

这些是我现在使用的实体:

有谁知道如何从这个实体创建 DTO 但没有“方法”字段?

查看 @JsonUnwrapped 注释 (https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonUnwrapped.html)。可以放在Beerclass中的method字段,然后Methodclass的属性直接在同级序列化来自 Beer.