Hi Paul,

answered, story short we should just import the ones from jsonb
modules (all are there I think) now master is java 8 - was the only
reason why it was not in mapper, because mapper was java 7.

A small side note: we can probably not break the java.util.Date
formatter which uses short iso8061 pattern instead of the long one.

Romain Manni-Bucau
@rmannibucau |  Blog | Old Blog | Github | LinkedIn


2017-10-14 15:10 GMT+02:00 Paul Carter-Brown <[email protected]>:
> Hi Romain,
>
> With JDK 1.8 becoming mainstream there will be a lot more use of
> java.time.Instant as the standard way of handling dates as opposed to
> java.util.date. In addition, rest services are standardising more and more
> on the ISO 8061 date format (e.g. 2007-12-03T17:15:30+03:00). I thus
> believe that Johnzon should support this out of the box  In this regard
> I've created a pull request for this functionality so it can be included in
> future TomEE releases https://github.com/apache/johnzon/pull/13
>
> I've use my fork on TomEE 7.0.4 and it now natively works with POJO's using
> Instant data type
>
> Paul
>
> On 14 October 2017 at 11:07, Romain Manni-Bucau <[email protected]>
> wrote:
>
>> that was the question ;)
>>
>> you can extend JohnzonProvider and pass it the mapper instance you
>> want - pre configured.
>>
>> Romain Manni-Bucau
>> @rmannibucau |  Blog | Old Blog | Github | LinkedIn
>>
>>
>> 2017-10-14 10:39 GMT+02:00 Paul Carter-Brown <paul.carter-brown@smilecoms.
>> com>:
>> > Yea bit of a false positive I'm afraid. I ended up getting it to be used
>> in
>> > a manual mapping operation and saw it was being called but unfortunately
>> > its not being used when called via jax-rs
>> >
>> > Will battle on a bit more before reverting to annotations
>> >
>> > On 14 October 2017 at 10:27, Romain Manni-Bucau <[email protected]>
>> > wrote:
>> >
>> >> Hmm, earlier in the boot process shouldn't change anything if you
>> >> manage yourself the builder, can you add why it impacted the behavior
>> >> please (for completeness of this thread)?
>> >>
>> >> side note: you can add annotations on generated jaxb models ->
>> >> https://github.com/highsource/jaxb2-annotate-plugin .
>> >>
>> >> Romain Manni-Bucau
>> >> @rmannibucau |  Blog | Old Blog | Github | LinkedIn
>> >>
>> >>
>> >> 2017-10-14 10:08 GMT+02:00 Paul Carter-Brown
>> <paul.carter-brown@smilecoms.
>> >> com>:
>> >> > 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 <
>> >> > [email protected]> 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 <
>> [email protected]>
>> >> >> 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"
>> >> <[email protected]
>> >> >>> 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
>> >> > [email protected]
>> >> > 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>
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> >
>> > *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
>> > [email protected]
>> > 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>
>> >
>>
>
>
>
> --
>
> *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
> [email protected]
> 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>
>

Reply via email to