tags:

views:

116

answers:

1

Hi,

I have a super abstract class:

@XmlSeeAlso({AndQuery.class, OrQuery.class, NotQuery.class, PropertyQuery.class, MultiQuery.class})
@XmlRootElement
public abstract class Query {

This class has a subclass:

public abstract class MultiQuery extends Query {

and this last super class has also two subclasses: AndQuery and OrQuery annotated with @XmlRootNode.

I also have a PropertyQuery class which extends Query super class.

All it's ok when i do a post like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                        <orQuery>
                            <query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
                                <propertyName>SenderContractNumber</propertyName>
                                <propertyValue>D*</propertyValue>
                            </query>
                           <query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
                                <propertyName>SenderContractNumber</propertyName>
                                <propertyValue>A*</propertyValue>
                            </query>
   <query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="andQuery">
                            <query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
                                <propertyName>documentNumber</propertyName>
                                <propertyValue>222</propertyValue>
                            </query>
                            <query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
                                <propertyName>documentNumber</propertyName>
                                <propertyValue>222</propertyValue>
                            </query>

</query>
</orQuery>

What i want is to POST an xml like this:

<orQuyery>
     <query>...</query>
     <andQuery>
         <query>...</query>
     </andQuery>
</orQuery>

insteand of what i put above.

Can you tell me please what i have to annotate because my OrQuery class expects to see only query nodes not and!

Please help...

Thanks a lot

+1  A: 

It sounds like you are trying to have many of your queries contain other queries. Let's just say, you want any MultiQuery to contain a list of other queries.

If you have just a List of type Query, JAXB will not be able to determine what types of queries you want to put into the list. You can specify all of the options for what the list can contain. This way the schema that is generated to allow any of the types of specified.

Example:

@XmlElements({
    @XmlElement(type=AndQuery.class),
    @XmlElement(type=OrQuery.class),
    @XmlElement(type=NotQuery.class),
    @XmlElement(type=PropertyQuery.class),
    @XmlElement(type=MultiQuery.class)
})
List<Query> queries;
Chris Dail