[Geoserver-devel] JSON output format and date/time formatting

Having an issue with the JSON output format and date/time formatting.

What I've gathered from the internet (?) is that JSON doesn't
prescribe a formatting for date/time objects up until May 26 2011 [1],
and now recommends date/times to be formatted as ISO 8601 dates
<http://www.w3.org/TR/NOTE-datetime&gt;

Customer is requiring date/times to be formatted as per as ISO 8601

Fix would be easy:
--- a/wfs/src/main/java/org/geoserver/wfs/response/GeoJSONBuilder.java
+++ b/wfs/src/main/java/org/geoserver/wfs/response/GeoJSONBuilder.java
@@ -250,4 +251,14 @@ public class GeoJSONBuilder extends JSONBuilder {
                 "Unable to determine geometry type " + geometry.getClass());
         }
     }
+
+
+ @Override
+ public GeoJSONBuilder value(Object value){
+ if(value instanceof java.util.Date){
+ value = Converters.convert(value, String.class);
+ }
+ super.value(value);
+ return this;
+ }

Any objection?

[1] <http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.23&gt;

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

On Wed, Oct 26, 2011 at 7:12 PM, Gabriel Roldan <groldan@anonymised.com…> wrote:

Having an issue with the JSON output format and date/time formatting.

What I’ve gathered from the internet (?) is that JSON doesn’t
prescribe a formatting for date/time objects up until May 26 2011 1,
and now recommends date/times to be formatted as ISO 8601 dates
<http://www.w3.org/TR/NOTE-datetime>

Customer is requiring date/times to be formatted as per as ISO 8601

Fix would be easy:
— a/wfs/src/main/java/org/geoserver/wfs/response/GeoJSONBuilder.java
+++ b/wfs/src/main/java/org/geoserver/wfs/response/GeoJSONBuilder.java
@@ -250,4 +251,14 @@ public class GeoJSONBuilder extends JSONBuilder {
"Unable to determine geometry type " + geometry.getClass());
}
}
+
+

  • @anonymised.com
  • public GeoJSONBuilder value(Object value){
  • if(value instanceof java.util.Date){
  • value = Converters.convert(value, String.class);
  • }
  • super.value(value);
  • return this;
  • }

Any objection?

Nothing in particular here, just an observation. In the past we had
complaints that OGR was not able to parse GeoJSON generated by
GeoServer 1, it would be interesting to know what happens with this
change

Cheers
Andrea

Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead

Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy

phone: +39 0584 962313
fax: +39 0584 962313

http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf


On Wed, Oct 26, 2011 at 7:30 PM, Andrea Aime <andrea.aime@anonymised.com.1268…> wrote:

Any objection?

Nothing in particular here, just an observation. In the past we had
complaints that OGR was not able to parse GeoJSON generated by
GeoServer [1], it would be interesting to know what happens with this
change

Uh, and maybe another observation too. Ian started a thread about timezones some
time ago, what happens timezone wise with this patch?
Also, I think some stores/parser can also generate Calendar objects, might want to
handle those as well in the patch.

Cheers
Andrea

Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead

Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy

phone: +39 0584 962313
fax: +39 0584 962313

http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf


On Wed, Oct 26, 2011 at 2:32 PM, Andrea Aime
<andrea.aime@anonymised.com> wrote:

On Wed, Oct 26, 2011 at 7:30 PM, Andrea Aime <andrea.aime@anonymised.com>
wrote:

Any objection?

Nothing in particular here, just an observation. In the past we had
complaints that OGR was not able to parse GeoJSON generated by
GeoServer [1], it would be interesting to know what happens with this
change

Uh, and maybe another observation too. Ian started a thread about timezones
some
time ago, what happens timezone wise with this patch?
Also, I think some stores/parser can also generate Calendar objects, might
want to
handle those as well in the patch.

Thanks Andrea.
So ogr2ogr seems happy. Run ogr2ogr -f GeoJSON out.json in.json on the
attached in.json produces the attached out.json

So granted there's no objection I'll prepare a patch that takes into
account Calendar (with timezone) and proper unit tests for review.

Cheers,
Gabriel

Cheers
Andrea

On Wed, Oct 26, 2011 at 3:29 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

Uh, and maybe another observation too. Ian started a thread about timezones
some
time ago, what happens timezone wise with this patch?

Forgot to properly answer this question: as far as this patch is
concerned, whether time zone handling has been properly made is not
this patch'es issue. That is, any piece of code creating a
java.util.Date, java.sql.Date/Time/Timestamp shall have taken care of
that before the Date/Time object instance reaches the encoder. And it
does that by taking into account the internal representation of ?
extends java.util.Date is always in GMT.

Cheers,
Gabriel

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

btw, good catch on asking what happens with Calendar instances,
because they're being encoded as:

"datetime_col":"java.util.GregorianCalendar[time=1317445261000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=\"GMT\",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=274,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=5,HOUR_OF_DAY=5,MINUTE=1,SECOND=1,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]"

On Wed, Oct 26, 2011 at 3:41 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

On Wed, Oct 26, 2011 at 3:29 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

Uh, and maybe another observation too. Ian started a thread about timezones
some
time ago, what happens timezone wise with this patch?

Forgot to properly answer this question: as far as this patch is
concerned, whether time zone handling has been properly made is not
this patch'es issue. That is, any piece of code creating a
java.util.Date, java.sql.Date/Time/Timestamp shall have taken care of
that before the Date/Time object instance reaches the encoder. And it
does that by taking into account the internal representation of ?
extends java.util.Date is always in GMT.

Cheers,
Gabriel

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

ON a related not it would be great to patch the geojson module in geotools as well. I will try to post a patch for that on the same issue.

On Wed, Oct 26, 2011 at 7:50 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

btw, good catch on asking what happens with Calendar instances,
because they’re being encoded as:

“datetime_col”:“java.util.GregorianCalendar[time=1317445261000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=274,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=5,HOUR_OF_DAY=5,MINUTE=1,SECOND=1,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]”

On Wed, Oct 26, 2011 at 3:41 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

On Wed, Oct 26, 2011 at 3:29 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

Uh, and maybe another observation too. Ian started a thread about timezones
some
time ago, what happens timezone wise with this patch?
Forgot to properly answer this question: as far as this patch is
concerned, whether time zone handling has been properly made is not
this patch’es issue. That is, any piece of code creating a
java.util.Date, java.sql.Date/Time/Timestamp shall have taken care of
that before the Date/Time object instance reaches the encoder. And it
does that by taking into account the internal representation of ?
extends java.util.Date is always in GMT.

Cheers,
Gabriel


Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.


Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.


The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@anonymised.com Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev


Geoserver-devel mailing list
Geoserver-devel@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel


Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Cool, so would you take a look at the patch attached to
http://jira.codehaus.org/browse/GEOS-4829 and tell whether you see
something wrong?

On Thu, Oct 27, 2011 at 3:26 AM, Justin Deoliveira <jdeolive@anonymised.com> wrote:

ON a related not it would be great to patch the geojson module in geotools
as well. I will try to post a patch for that on the same issue.

On Wed, Oct 26, 2011 at 7:50 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

btw, good catch on asking what happens with Calendar instances,
because they're being encoded as:

"datetime_col":"java.util.GregorianCalendar[time=1317445261000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=\"GMT\",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=274,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=5,HOUR_OF_DAY=5,MINUTE=1,SECOND=1,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]"

On Wed, Oct 26, 2011 at 3:41 PM, Gabriel Roldan <groldan@anonymised.com>
wrote:
> On Wed, Oct 26, 2011 at 3:29 PM, Gabriel Roldan <groldan@anonymised.com>
> wrote:
>>> Uh, and maybe another observation too. Ian started a thread about
>>> timezones
>>> some
>>> time ago, what happens timezone wise with this patch?
> Forgot to properly answer this question: as far as this patch is
> concerned, whether time zone handling has been properly made is not
> this patch'es issue. That is, any piece of code creating a
> java.util.Date, java.sql.Date/Time/Timestamp shall have taken care of
> that before the Date/Time object instance reaches the encoder. And it
> does that by taking into account the internal representation of ?
> extends java.util.Date is always in GMT.
>
> Cheers,
> Gabriel
>
>
> --
> Gabriel Roldan
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
>

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@anonymised.com Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.

On Fri, Oct 28, 2011 at 9:17 PM, Gabriel Roldan <groldan@anonymised.com> wrote:

Cool, so would you take a look at the patch attached to
http://jira.codehaus.org/browse/GEOS-4829 and tell whether you see
something wrong?

Looks good to me

Cheers
Andrea

--
-------------------------------------------------------
Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead

Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy

phone: +39 0584 962313
fax: +39 0584 962313

http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf

-------------------------------------------------------