是否可以配置Dozer,以便默认情况下通过setter- / getter方法直接访问字段 [英] Is it possible to configure Dozer such that by default fields are rather accessed directly that through setter-/getter method
问题描述
我必须映射一个复杂的Java类结构,它通常不会通过set- / get-methods暴露它们的字段(这是给定的,不能更改)。
因此映射只能在直接字段访问上执行。推土机允许个别字段可访问,但我没有找到设置使这成为一般行为。因此,我不必为了使其可访问而明确映射每个字段!
I have to map a complex structure of Java classes which don't expose their fields through set-/get-methods in general (this is given and can't be changed). So mapping can only be performed on a direct field access. Dozer allows individual fields to be made accessible but I haven't found a setting to make this the general behaviour. As a result I wouldn't have to map each field explicitly just for making it accessible!
此选项是否存在?
- 在班级?
- 在全球范围内?
Does this option exist? - On a class level? - On a global level?
推荐答案
您可以在班级设置它。
<mapping>
<class-a is-accessible="true">MyClass</class-a>
...
</mapping>
来自Dozer XSD:
From the Dozer XSD:
is-accessible指示Dozer是否绕过getter / setter方法并直接访问该字段。这通常设置为false。默认值为false。如果设置为true,则不会调用
getter / setter方法。如果字段缺少getter或setter方法,您可能希望将其设置为true。
is-accessible Indicates whether Dozer bypasses getter/setter methods and accesses the field directly. This will typically be set to "false". The default value is "false". If set to "true", the getter/setter methods will NOT be invoked. You would want to set this to "true" if the field is lacking a getter or setter method.
这篇关于是否可以配置Dozer,以便默认情况下通过setter- / getter方法直接访问字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!