在micronaut 2.1.2中获取POJO属性名称

问题描述

试图在Micronaut应用程序中获取POJO属性名称我有下面的POJO课

@Introspected
public class Product {
    @BsonProperty("_id")
    @BsonId
    private ObjectId id;
    private String name;
    private float price;
    private String description;

    // Getter and setter
}

我知道我们可以使用Introspected

下面的代码以数组形式为我提供了所有属性

 final BeanIntrospection<Product> introspection = BeanIntrospection.getIntrospection(Product.class);
 var product = introspection.getPropertyNames();

现在产品包含属性名称字符串,

[0] name
[1] price
[2] description

我需要获取以下单个属性,而不是在product

上进行foreach

除了通过数组之外,还有什么方法可以直接访问它,类似于下面的Lombok

var desc = Product.Fields.description
var name = Product.Fields.name
var price = Product.Fields.price

有什么办法可以做到这一点?

解决方法

有没有办法访问数组,而不是通过数组 与龙目岛直接相似,如下所示:

var desc = Product.Fields.description 
var name = Product.Fields.name
var price = Product.Fields.price

不。没有这样的API来支持这样的语法。