Hi Sergey,

 

Adding the adapter to the DateField class works if I send this class as a
root of my payload. However, if other class has a DateField within a List
(this is my real scenario) the adapter is not activated. If I add the
adapter either to the package level or the field/property level, a
JAXBException is thrown:

 

Payload: JAXBException occurred : unexpected element (uri:"",
local:"priority"). Expected elements are <{}genericBean>. unexpected element
(uri:"", local:"priority"). Expected elements are <{}genericBean>.

 

This is the payload, which works with XMLGregorioanCalendarImpl if I don’t
annotate any field/property with the adapter:

 

<?xml version="1.0" encoding="utf-8" ?>

<priority xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>

<fieldList>

<field xsi:type="dateField"> 

   <maxValue>2011-04-12T15:51:37.489+02:00</maxValue>

   <value xsi:type="xs:dateTime">2011-04-12T15:51:37.977+02:00</value>

</field>

</fieldList>

</priority>

 

Thanks for your patience… :P

 

Cheers!

 

Ivan

 

¡De: Sergey Beryozkin [mailto:[email protected]] 
Enviado el: martes, 12 de abril de 2011 16:27
Para: Ivan Vitoria Sanchez
CC: [email protected]
Asunto: Re: Using Date instead of XmlGregorianCalendarImpl

 

Hi Ivan

I think you should then add the adapter to the DateField class itself, to
the maxValue field, or add it to package-info.java, that should fix it

thanks, Sergey

On Tue, Apr 12, 2011 at 3:09 PM, Ivan Vitoria Sanchez
<[email protected]> wrote:

Hi Sergey,

 

It’s the same scenario that you have seen before in other JIRAs. At this
time, I’m trying to put/post data. There is no problem if my POJO (annotated
with @XmlRootElement) has Date attributes:

 

<workOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>

      <completionDate>2015-02-27T17:08:46.300+01:00</completionDate>

<!-- other tags omitted -->

</workOrder>

 

The problem comes when I’ve this kind of entity:

 

public abstract class InputField<T> extends GenericBean<InputField<T>>

{

                T value;

                // getter & setter omitted

}

 

public class DateField extends InputField<Date>

{

                private Date maxValue;

                // getter & setter omitted

}

 

And my XML looks like this:

 

<dateField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>

   <maxValue>2011-04-12T15:51:37.489+02:00</maxValue>

   <value xsi:type="xs:dateTime">2011-04-12T15:51:37.977+02:00</value>

</dateField>

 

It seems as if the Java instance becomes
InputField<XMLGregorianCalendarImpl> instead of DateField.

 

Hope this helps!

 

Cheers,

 

Ivan

 

De: Sergey Beryozkin [mailto:[email protected]] 
Enviado el: martes, 12 de abril de 2011 15:16


Para: [email protected]

CC: Ivan Vitoria Sanchez


Asunto: Re: Using Date instead of XmlGregorianCalendarImpl

 

Hi Ivan

On Mon, Apr 11, 2011 at 3:19 PM, Ivan Vitoria Sanchez
<[email protected]> wrote:

Hi Sergey,

The problem is that my method returns T, which is resolved by
XMLGregorianCalendar instead of Date.

Is this method a JAX-RS resource method ? Or is it part of the JAXB bean
class ?
I don't think returning a Date directly from a resource method would work
with JAXBElementProvider 

Adding a @XmlJavaTypeAdapter to the method with a custom XmlAdapter causes a
JAXBException (unexpected element).

Can you provide more info please ?

thanks, Sergey
 

Ivan


-----Mensaje original-----
De: Sergey Beryozkin [mailto:[email protected]]
Enviado el: lunes, 11 de abril de 2011 12:45
Para: [email protected]
Asunto: Re: Using Date instead of XmlGregorianCalendarImpl


Hi Ivan

You have to add an adapter, please see

http://blogs.sun.com/CoreJavaTechTips/entry/exchanging_data_with_xml_and

for an example.

JAXBElementProvider won't check package-level adapters, at the moment you'll
probably need to add it to a method returning a Date. I'll see what has be
improved for package-level adapters be checked too

Cheers, Sergey

On Mon, Apr 11, 2011 at 9:25 AM, Ivan Vitoria Sanchez <[email protected]
> wrote:

> Hello,
>
>
>
> Is there any way to configure (via Spring) the JAXB provider in order to
> use
> "Date" instead of "XmlGregorianCalendarImpl" in the JAX-RS server? I'm
> having XmlGregorianCalendarImpl instances when using a class which extend
> from a generic type class and specifying Date as the type in my subclass.
>
>
>
> Many thanks,
>
>
>
> Ivan
>
>
>
>




-- 
Sergey Beryozkin

Application Integration Division of Talend <http://www.talend.com> 
http://sberyozkin.blogspot.com

 

Reply via email to