简体   繁体   English

Jibx生成toString方法

[英]Jibx generating toString method

I'm currently using the Jibx maven plugin to codegen Java POJOS from a defined schema. 我目前正在使用Jibx maven插件从已定义的模式对Java POJOS进行代码生成。 The code gets generated fine, but what I want is for the toString method to be generated too. 代码可以很好地生成,但是我想要的是也可以生成toString方法。 As I am round tripping from Schema to Classes I cant manually define the toString method as this will get overwritten when I re-generate. 当我从模式到类往返时,我无法手动定义toString方法,因为当我重新生成时,它将被覆盖。 And I don;t want to create a wrapper class just for the toString methods. 而且我不想只为toString方法创建包装器类。

Is there a flag option or something somewhere to say I want the toString method to be generated??? 是否有一个标志选项或某处要说的东西我想生成toString方法??? I've looked at the Jibx documentation online and could not find a straight simple answer to the above. 我在网上查看了Jibx文档,但找不到上述内容的简单答案。

Any help would be very much appreciated. 任何帮助将不胜感激。

thanks so much 非常感谢

user983022, 用户983022,
There is no automatic way to add code to a generated java clas in JiBX, but... 在JiBX中没有自动将代码添加到生成的Java clas的自动方法,但是...
You have several options to solve this problem: 您可以通过几种方法解决此问题:

  1. Override your generated class and add the toString() method. 覆盖您生成的类并添加toString()方法。 (Easiest) (最简单的)
  2. Manually modify the generated code and then bind it with JiBX. 手动修改生成的代码,然后将其与JiBX绑定。 (Breaks if the schema changes in the future) (如果将来更改架构,则会中断)
  3. Add a maven plugin to modify the source code between the code generation and the binding step. 添加一个maven插件以在代码生成和绑定步骤之间修改源代码。 I'm sure there's a sed-like plugin that can do this... if not, it would be easy to write. 我确定有一个类似sed的插件可以做到这一点...如果没有,那将很容易编写。 (You have to find/write a plugin that can do this) (您必须找到/编写可以执行此操作的插件)

I Hope this helps! 我希望这有帮助!

Don
JiBX Maven plugin author JiBX Maven插件作者

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

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