tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Carter-Brown <paul.carter-br...@smilecoms.com>
Subject Re: Registering Mapper in Johnzon
Date Sat, 14 Oct 2017 08:08:44 GMT
Hi Romain,

I managed to get it to work by calling new MapperBuilder().addAdapter(new
JavascriptDate()).build(); far earlier in the bootup process.

On 14 October 2017 at 09:40, Paul Carter-Brown <
paul.carter-brown@smilecoms.com> wrote:

> Hi Romain,
>
> The model is generated using jaxb from an XSD. Jaxb has been set up to map
> xs:dateTime to java.time.Instant
>
> getters/setters look like this:
>     public Instant getDate() {
>         return date;
>     }
>
>     public void setDate(Instant value) {
>         this.date = value;
>     }
>
> As the model is generated I don't have the option of adding annotations on
> it and need to configure Johnzon to globally deal with Instant data type
>
> Paul
>
> On 14 October 2017 at 09:36, Romain Manni-Bucau <rmannibucau@gmail.com>
> wrote:
>
>> Hi
>>
>> What is your model?
>>
>> Did you try @JohnzonConverter too?
>>
>> Tomee uses an old johnzon too so can need some enhancements from master.
>>
>> Le 14 oct. 2017 03:10, "Paul Carter-Brown" <paul.carter-brown@smilecoms.c
>> om>
>> a écrit :
>>
>> > Hi,
>> >
>> > I've created an adapter as follows:
>> >
>> > public class JavascriptDate implements Adapter<String, Instant> {
>> >
>> >     @Override
>> >     public String to(Instant instance) {
>> >         final Calendar cal = GregorianCalendar.getInstance();
>> >         cal.setTime(Date.from(instance));
>> >         return DatatypeConverter.printDateTime(cal);
>> >     }
>> >
>> >     @Override
>> >     public Instant from(String text) {
>> >         return DatatypeConverter.parseDateTime(text).getTime().
>> > toInstant();
>> >     }
>> > }
>> >
>> > and register it globally like this in a servlet init:
>> >
>> > new MapperBuilder().addAdapter(new JavascriptDate()).build();
>> >
>> > When I call a rest service passing a date formatted string field that
>> needs
>> > to map to an Instant I get an error:
>> >
>> > org.apache.johnzon.mapper.MapperException: Using fallback converter,
>> this
>> > only works in write mode but not in read. Please register a custom
>> > converter to do so.
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl$FallbackConverte
>> r.fromString(
>> > MappingParserImpl.java:715)
>> > at org.apache.johnzon.mapper.internal.ConverterAdapter.to
>> > (ConverterAdapter.java:37)
>> > at org.apache.johnzon.mapper.internal.ConverterAdapter.to
>> > (ConverterAdapter.java:24)
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl.convertTo(
>> > MappingParserImpl.java:682)
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl.toObject(
>> > MappingParserImpl.java:523)
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl.toValue(
>> > MappingParserImpl.java:634)
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl.buildObject(
>> > MappingParserImpl.java:318)
>> > at
>> > org.apache.johnzon.mapper.MappingParserImpl.readObject(
>> > MappingParserImpl.java:133)
>> >
>> >
>> > Any ideas why my mapper is not being used?
>> >
>> > Thanks
>> > Paul
>> >
>> > --
>> >
>> >
>> > This email is subject to the disclaimer of Smile Communications at
>> > http://www.smilecoms.com/home/email-disclaimer/ <
>> http://www.smilecoms.com/
>> > disclaimer>
>> >
>> >
>>
>
>
>
>
>


-- 

*Paul Carter-Brown*

*Group Chief Information Officer*

*Smile Communications Pty (Ltd)       *
Smile +234 (0) 702 000 1234
Mobile +27 (0) 83 4427 179
Skype PaulC-B
paul.carter-brown@smilecoms.com
www.smilecoms.com

-- 


This email is subject to the disclaimer of Smile Communications at http://www.smilecoms.com/home/email-disclaimer/
<http://www.smilecoms.com/disclaimer>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message