Comments (12)
Is there already a choice annotation?
I took a short look at validation-api but did't find it.
If it does not exist and i should add it which package should i use for that?
Using as selfmade annotation has the disadvantage of commonly being not supported by validators.
from krasa-jaxb-tools.
I just pushed the annotation into a new branch, validation-api does not have anything usefull.
The validation should work out of the box, at least with hibernate validator, that is fine by me.
from krasa-jaxb-tools.
I guess it is a good start, but if i have a look at the given example i could thing of situations where more than one choice is possible
<xs:complexType name="DrinkType">
<xs:sequence>
<xs:choice>
<xs:element ref="Tea"/>
<xs:element ref="Coffee"/>
</xs:choice>
<xs:choice>
<xs:element ref="Honey"/>
<xs:element ref="Sugar"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
which should result in:
@Choice.List({
@Choice({"tea", "coffee"}),
@Choice({"honey", "sugar"})
})
public class DrinkType {
Tea tea;
Coffee coffee;
Honey honey;
Sugar sugar;
}
Similar to @Pattern.List
from krasa-jaxb-tools.
And we should have an eye on this one:
http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html
Especially for List of Choices with MaxOccurs>1
@XmlElements(value = {
@XmlElement(name="address",
type=Address.class),
@XmlElement(name="phone-number",
type=PhoneNumber.class),
@XmlElement(name="note",
type=String.class)
})
private List<Object> contactInfo;
Is this output even possible when using xsd->java conversion?
from krasa-jaxb-tools.
@Choice.List - exactly.
You can get choice as a single field:
http://blog.bdoughan.com/2011/04/xml-schema-to-java-xsd-choice.html
krasa/krasa-jaxb-tools-example@db6ccb8
But I do not like this thing.
from krasa-jaxb-tools.
I think both possibilities make sense somehow.
Especially if the first one is the default option for the converter.
In addition to that:
The @Choice
annotation needs a min and max Count field
from krasa-jaxb-tools.
Interesting, it generates the second style if it has maxOccurs...krasa/krasa-jaxb-tools-example@e654800
But I would not bother with supporting that, since I have never seen such thing, even simple choice is quite rare.
from krasa-jaxb-tools.
Hi
I use Krasa in one of my projects and wondered how far the progress was with this choice validation...it would be extremely useful.
thanks
from krasa-jaxb-tools.
hi, the progress is: I am pretty sure that it cannot be done without some manual parsing of the xsd, or some xsd annotations, which sucks.
from krasa-jaxb-tools.
HI, I recently checked out https://github.com/krasa/krasa-jaxb-tools-example and noticed that if I set a maxOccurs to something other than 1, choices got generated almost as I would expect ie:
@XmlElementRefs({
@XmlElementRef(name = "Tea", namespace = "a", type = JAXBElement.class),
@XmlElementRef(name = "Coffee", namespace = "a", type = JAXBElement.class)
})
@Size(min = 1, max = 2)
protected List<Object> teaOrCoffee;
or if I comment the entry in bindings.xml:-
@XmlElements({
@XmlElement(name = "Tea", type = Tea.class),
@XmlElement(name = "Coffee", type = Coffee.class)
})
@Size(min = 1, max = 2)
protected List<Object> teaOrCoffee;
I just wondered why I can't get the same output without specifying a maxOccurs or even with specifying a maxOccurs of 1? Surely a choice implicitly means you only want one of them? What I really want is the following:
@XmlElements({
@XmlElement(name = "Tea", type = Tea.class),
@XmlElement(name = "Coffee", type = Coffee.class)
})
private Object teaOrCoffee;
PS. thank you for a great plugin, aside from the choice issue, all works beautifully!
from krasa-jaxb-tools.
any updates on this?
from krasa-jaxb-tools.
no, sorry :(
from krasa-jaxb-tools.
Related Issues (20)
- Plugin crashes with NPE at fields with final static (fixed value) HOT 3
- minExclusive=0, fractionDigits=2 wrong annotation HOT 1
- Krasa - JAXB : Wrong @Digit validation attribute with totalDigits & fractionDigits (XSD) HOT 16
- xs:enumeration is not translated correctly to annotations HOT 8
- Exception thrown if XSD union is used HOT 4
- XReplacePrimitives not converting doubles and floats
- Pattern Validation for enums. At the moment Krasa supports only String type for Patterns HOT 2
- Plugin throws RTE on XReplacePrimitives for serialVersionUID HOT 2
- Tagged releases HOT 1
- Do not use @Pattern.List for multiple patterns
- Further support for krasa-jaxb-tools HOT 1
- Bug in @Digits annotations HOT 1
- Multiple Patterns with own base-restriction-simpletype is ignored HOT 1
- Attributes don't seem to be annotated unless they have a minOccurs > 0 HOT 1
- 1.7 branch release HOT 1
- @Size for ArrayList/Collections/Maps
- Traversing super classes in loop iterates over wrong variable
- Enumeration pattern is not escaped HOT 2
- Wrong integral digits in Digit-Annotation in combination of totalDigits and fractionDigits in XSD HOT 1
- Is the plugin executable from cmd line without need of maven? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from krasa-jaxb-tools.