# HG changeset patch # User Babis Nikolaou # Date 1414676260 -7200 # Node ID 025b64f6f1faba7cb13bda05a946fb11832e8e11 # Parent 54679bf9f89b06aaa00ff25eee2cb8ea8dd98baf adresses bug #75: now GeoJSON correctly prints a datatype literal value, instead of always printing it as a string diff -r 54679bf9f89b -r 025b64f6f1fa resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Thu Oct 30 15:36:00 2014 +0200 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Thu Oct 30 15:37:40 2014 +0200 @@ -13,6 +13,7 @@ import java.io.OutputStream; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import org.geotools.data.simple.SimpleFeatureCollection; @@ -24,9 +25,8 @@ import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.openrdf.model.Literal; +import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.impl.LiteralImpl; -import org.openrdf.model.impl.URIImpl; import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.TupleQueryResultHandlerException; @@ -215,6 +215,7 @@ properties.add(binding.getName()); values.add(value); + System.out.println(value.getClass()); } } @@ -224,7 +225,32 @@ // add the properties for (int p = 0; p < properties.size(); p++) { - sftb.add(properties.get(p), String.class); + Value val = values.get(p); + + if (val instanceof Literal) { + Literal lit = (Literal) val; + URI datatype = lit.getDatatype(); + + if (XMLGSDatatypeUtil.isNumericDatatype(datatype)) { + System.out.println("is number"); + sftb.add(properties.get(p), Number.class); + + } else if (XMLGSDatatypeUtil.isCalendarDatatype(datatype)) { + System.out.println("is calendar"); + sftb.add(properties.get(p), Calendar.class); + + } else if (XMLGSDatatypeUtil.isBooleanDatatype(datatype)) { + System.out.println("is boolean"); + sftb.add(properties.get(p), Boolean.class); + + } else { // fallback to String + sftb.add(properties.get(p), String.class); + } + + } else { // fallback to String + sftb.add(properties.get(p), String.class); + } + } SimpleFeatureType featureType = sftb.buildFeatureType(); @@ -235,7 +261,7 @@ // add the values to the builder of the feature for (int v = 0; v < values.size(); v++) { - featureBuilder.add(values.get(v)); + featureBuilder.add(values.get(v).stringValue()); } SimpleFeature feature = featureBuilder.buildFeature(null);