NeTEx icon indicating copy to clipboard operation
NeTEx copied to clipboard

Generate POJOs from XSD

Open VincentX66 opened this issue 5 years ago • 8 comments

Hi, guys,

has anyone managed to generate code from the xsd? I tried with xmlbeans and xjc (jaxb), but only get error messages (like that something is already in use or collisions). I've already looked for solutions, but unfortunately found none. It kept saying, "use the xsd to generate classes".

VincentX66 avatar Jul 14 '20 11:07 VincentX66

@VincentX66 this is why you always should ask questions like this :) It is done, and currently maintained:

https://github.com/entur/netex-java-model

skinkie avatar Jul 14 '20 12:07 skinkie

@skinkie Thank you for your quick answer and your correction of my question. Sorry, never used GitHub before. Anyway, https://github.com/entur/netex-java-model doesn't work for me. A problem with the maven-exec-plugin and that it's not a windows application. I don't know if I should go into more detail or note it in the appropriate github repository.

VincentX66 avatar Jul 15 '20 10:07 VincentX66

I think it is better to ask there. But the command "mvn" should work on windows as well. Worst case you can obviously run this in Linux generate the classes ;-)

Or use the precompiled code: https://mvnrepository.com/artifact/org.entur/netex-java-model/1.0.9

skinkie avatar Jul 15 '20 10:07 skinkie

Hello Stefan,

I looked at your bindings.xjb and would have a comment for you. The xsd:duration is assigned to java.time.Duration, but java.time.Duration cannot handle the full format specified in the standard. See: https://www.w3.org/TR/xmlschema-2/#duration https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-

We use javax.xml.datatype.Duration.

janosu avatar Jul 16 '20 19:07 janosu

@janosu please inform entur about this in their repository. But in all reasonability, will a duration in transit ever be more than a day?

skinkie avatar Jul 16 '20 19:07 skinkie

Yes, it can be more than one day (eg.: for a train to Moscow), but it is not only in this field that the duration type can be. For example, in the case of tickets, season tickets, where the period of validity can be specified, which can be more than one day, eg: 3 months, half a year, etc.

So in general, in xsd: duration you can specify a year and a month in addition to the days and times that java.time.Duration can't handle.

janosu avatar Jul 16 '20 20:07 janosu

@janosu the current Duration type just encodes it to seconds and nanoseconds right? No further limitations? Or is the parsing an issue?

skinkie avatar Jul 16 '20 21:07 skinkie

Yes, just encodes it to seconds and nanoseconds. Look at the source code. Another example: See https://www.baeldung.com/java-period-duration The duration between dates is handled by java.time.Period.

The java.time.Duration can parse "PnDTnHnMn.nS", but W3C xs:duration can be "-PnYnMnDTnHnMn.nS". See https://www.w3schools.com/xml/schema_dtypes_date.asp

There is no problem with java.time.Duration as long as it is filled in your interpretation range, only it is not completely standard.

janosu avatar Jul 17 '20 07:07 janosu