Linux 执行自定义转换器时访问父类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing parent class when doing custom converter
提问by ballmw
I am currently using Dozer to map to sets of objects.
我目前正在使用 Dozer 映射到对象集。
I have a situation where I need to use a custom converter to map a String to TypeA.
我有一种情况需要使用自定义转换器将字符串映射到 TypeA。
The way I convert TypeA to a String depends on the type of Object TypeA is a member of.
我将 TypeA 转换为 String 的方式取决于 TypeA 所属的对象类型。
Specifically TypeA has 2 fields lets call them prefixand postfix. Sometimes I need to split the String by a space, or dash or slash. That character to split on is defined in the parent of TypeA.
具体而言,TypeA 有 2 个字段,可以称它们为prefix和postfix。有时我需要用空格、破折号或斜线分割字符串。要拆分的字符在 TypeA 的父级中定义。
Is there a way to do this in Dozer with custom converters? I need to go up the chain...
有没有办法在带有自定义转换器的推土机中做到这一点?我需要上链...
Thanks in advance for any help.
在此先感谢您的帮助。
采纳答案by Blake
So you should map a String to the parent of TypeA. In your xml file, to get to the "prefix" and "postfix" you would type, parent.TypeA.prefix
or parent.TypeA.postfix
. Hope this helps.
所以你应该将一个字符串映射到 TypeA 的父级。在您的 xml 文件中,要获得“前缀”和“后缀”,您可以键入,parent.TypeA.prefix
或parent.TypeA.postfix
. 希望这可以帮助。