xjc の OpenJDK 実装はcom.sun.xml.internal.bind.api.impl.NameConverter#toVariableName
、プロパティ名をメンバー変数名に変換するために使用します。変数名を「そのまま」にできる実装はないようです。該当する場合は、独自の xjc プラグインを作成して、プライベート プロパティ名をそのパブリック名に設定できます。プラグインは次のようになります。
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.Plugin;
import com.sun.tools.xjc.model.CClassInfo;
import com.sun.tools.xjc.model.CPropertyInfo;
import com.sun.tools.xjc.model.Model;
import com.sun.tools.xjc.outline.Outline;
public class XJCPlugin extends Plugin {
@Override
public String getOptionName() {
return "XsameElementNames";
}
@Override
public int parseArgument(Options opt, String[] args, int i) {
return 1;
}
@Override
public String getUsage() {
return " -XsameElementNames : set property private name as its public name";
}
@Override
public void postProcessModel(Model model, ErrorHandler errorHandler) {
for (CClassInfo c : model.beans().values()) {
for (CPropertyInfo prop : c.getProperties()) {
prop.setName(false, prop.getName(true));
}
}
}
@Override
public boolean run(Outline arg0, Options arg1, ErrorHandler arg2) throws SAXException {
return true;
}
}