简体   繁体   English

jibx:如何从自动生成的Java集合中删除单词“ List”?

[英]jibx : how to remove the word “List” from auto generated java collections?

I'm using jibx to auto generate java classed based on a xsd schema. 我正在使用jibx自动生成基于xsd模式分类的java。 In this schema I have a collection called markets: 在此模式下,我有一个称为市场的集合:

<xs:element maxOccurs="unbounded" minOccurs="0"
name="markets" nillable="true" type="market"/>

When I run jibx (using maven plugin) the result is a java class with the following collection: 当我运行jibx(使用maven插件)时,结果是一个带有以下集合的Java类:

 private List<Market> marketList = new ArrayList<Market>();
/** 
     * Get the list of 'markets' element items.
     * 
     * @return list
     */
    public List<Market> getMarketList() {
        return marketList;
    }

    /** 
     * Set the list of 'markets' element items.
     * 
     * @param list
     */
    public void setMarketList(List<Market> list) {
        marketList = list;
    }

What I'd like to have is the name of the element and the getter and setter without the word List, but instead with the word markets setMarkets() and getMarkets(). 我想要的是元素的名称以及不带有List的getter和setter,而是带有markets setMarkets()和getMarkets()的单词。

I know I can specify a custom file in the pom.xml : 我知道我可以在pom.xml中指定一个自定义文件:

<customizations>
<customizations>src/main/config/custom1.xml</customizations>
</customizations>

But I don't know how to specify the behavior I need in the custom1.xml. 但是我不知道如何在custom1.xml中指定所需的行为。

Any idea on this? 有什么想法吗?

Marco, 马可
You are correct, you need to use an extension customization. 您是正确的,您需要使用扩展程序自定义。 There are two ways to replace the method name: 有两种方法可以替换方法名称:

  1. Use the strip-suffixes command. 使用strip-suffixes命令。
    Your customization file would look something like this 您的自定义文件如下所示
    <schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <name-converter strip-suffixes="List"/>
    </schema-set>>

  2. Write a name-converter 写一个名字转换器
    If you want your method to be getMarkets instead of getMarket. 如果您希望您的方法是getMarkets而不是getMarket。

Here's the documentation for what you want to do from the JiBX web site: 这是您要从JiBX网站上执行的操作的文档:
http://jibx.sourceforge.net/fromschema/codegen-extends.html http://jibx.sourceforge.net/fromschema/codegen-extends.html
Don
JiBX contributor JiBX贡献者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM