You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Günther Schmidt <gu...@web.de> on 2012/05/23 18:21:03 UTC
Sling JSON import date formats
Hi,
I'm using JSON to import more complex data structures into sling. I
can't seem to manage to import dates as "Date", they always arrive as
strings. I did use "EEE MMM dd yyyy HH:mm:ss 'GMT'Z" as the format. I
also tried adding a typehint but that does not seem to work for JSON
imports either.
What's the trick to get a date into sling via JSON import?
Günther
Re: Sling JSON import date formats
Posted by "David G." <da...@gmail.com>.
Looks right - I believe its the ISO 8601DZ DateTime format - if memory serves.
--
David Gonzalez
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Wednesday, May 23, 2012 at 1:37 PM, Günther Schmidt wrote:
> Hi David,
>
> thanks, I found it in the meantime.
> The pattern
>
> yyyy-MM-dd'T'HH:mm:ss.SSSZ
>
> did it for me.
>
> Günther
>
> Am 23.05.12 19:32, schrieb David G.:
> > Gunter,
> >
> > Check out the org.apache.sling.jcr.contentloader.internal.readers;JSONReader.java class in the Sling proj.
> >
> >
> > Your input date string has to match the pattern below.
> >
> > private static final Pattern jsonDate = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}[-+]{1}[0-9]{2}[:]{0,1}[0-9]{2}$");
> >
> > ….
> >
> > if (jsonDate.matcher((String) object).matches()) return PropertyType.DATE;
> >
> >
> > Try running your inputs against that regex and see how it fares.
> >
> > Cheers
> >
> > --
> >
> > David Gonzalez
> > Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> >
> >
> > On Wednesday, May 23, 2012 at 12:21 PM, Günther Schmidt wrote:
> >
> > > Hi,
> > >
> > > I'm using JSON to import more complex data structures into sling. I
> > > can't seem to manage to import dates as "Date", they always arrive as
> > > strings. I did use "EEE MMM dd yyyy HH:mm:ss 'GMT'Z" as the format. I
> > > also tried adding a typehint but that does not seem to work for JSON
> > > imports either.
> > >
> > > What's the trick to get a date into sling via JSON import?
> > >
> > > Günther
Re: Sling JSON import date formats
Posted by Günther Schmidt <gu...@web.de>.
Hi David,
thanks, I found it in the meantime.
The pattern
yyyy-MM-dd'T'HH:mm:ss.SSSZ
did it for me.
Günther
Am 23.05.12 19:32, schrieb David G.:
> Gunter,
>
> Check out the org.apache.sling.jcr.contentloader.internal.readers;JSONReader.java class in the Sling proj.
>
>
> Your input date string has to match the pattern below.
>
> private static final Pattern jsonDate = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}[-+]{1}[0-9]{2}[:]{0,1}[0-9]{2}$");
>
> ….
>
> if (jsonDate.matcher((String) object).matches()) return PropertyType.DATE;
>
>
> Try running your inputs against that regex and see how it fares.
>
> Cheers
>
> --
>
> David Gonzalez
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
>
>
> On Wednesday, May 23, 2012 at 12:21 PM, Günther Schmidt wrote:
>
>> Hi,
>>
>> I'm using JSON to import more complex data structures into sling. I
>> can't seem to manage to import dates as "Date", they always arrive as
>> strings. I did use "EEE MMM dd yyyy HH:mm:ss 'GMT'Z" as the format. I
>> also tried adding a typehint but that does not seem to work for JSON
>> imports either.
>>
>> What's the trick to get a date into sling via JSON import?
>>
>> Günther
>
Re: Sling JSON import date formats
Posted by "David G." <da...@gmail.com>.
Gunter,
Check out the org.apache.sling.jcr.contentloader.internal.readers;JSONReader.java class in the Sling proj.
Your input date string has to match the pattern below.
private static final Pattern jsonDate = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}[-+]{1}[0-9]{2}[:]{0,1}[0-9]{2}$");
….
if (jsonDate.matcher((String) object).matches()) return PropertyType.DATE;
Try running your inputs against that regex and see how it fares.
Cheers
--
David Gonzalez
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Wednesday, May 23, 2012 at 12:21 PM, Günther Schmidt wrote:
> Hi,
>
> I'm using JSON to import more complex data structures into sling. I
> can't seem to manage to import dates as "Date", they always arrive as
> strings. I did use "EEE MMM dd yyyy HH:mm:ss 'GMT'Z" as the format. I
> also tried adding a typehint but that does not seem to work for JSON
> imports either.
>
> What's the trick to get a date into sling via JSON import?
>
> Günther