Giter VIP home page Giter VIP logo

Comments (12)

ST-DDT avatar ST-DDT commented on August 12, 2024

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.

krasa avatar krasa commented on August 12, 2024

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.

ST-DDT avatar ST-DDT commented on August 12, 2024

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.

ST-DDT avatar ST-DDT commented on August 12, 2024

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.

krasa avatar krasa commented on August 12, 2024

@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.

ST-DDT avatar ST-DDT commented on August 12, 2024

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.

krasa avatar krasa commented on August 12, 2024

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.

Angc288 avatar Angc288 commented on August 12, 2024

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.

krasa avatar krasa commented on August 12, 2024

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.

mandyWW avatar mandyWW commented on August 12, 2024

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.

mandyWW avatar mandyWW commented on August 12, 2024

any updates on this?

from krasa-jaxb-tools.

krasa avatar krasa commented on August 12, 2024

no, sorry :(

from krasa-jaxb-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.