Changeset 16936 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java
r15905 r16936 2 2 package org.openstreetmap.josm.io; 3 3 4 import java.io.StringReader; 4 5 import java.io.StringWriter; 5 6 import java.math.BigDecimal; … … 22 23 import javax.json.JsonWriter; 23 24 import javax.json.stream.JsonGenerator; 25 import javax.json.stream.JsonParser; 26 import javax.json.stream.JsonParsingException; 24 27 25 28 import org.openstreetmap.josm.data.Bounds; … … 55 58 56 59 /** 60 * This is used to determine that a tag should be interpreted as a json 61 * object or array. The tag should have both {@link #JSON_VALUE_START_MARKER} 62 * and {@link #JSON_VALUE_END_MARKER}. 63 */ 64 static final String JSON_VALUE_START_MARKER = "{"; 65 /** 66 * This is used to determine that a tag should be interpreted as a json 67 * object or array. The tag should have both {@link #JSON_VALUE_START_MARKER} 68 * and {@link #JSON_VALUE_END_MARKER}. 69 */ 70 static final String JSON_VALUE_END_MARKER = "}"; 71 72 /** 57 73 * Constructs a new {@code GeoJSONWriter}. 58 74 * @param ds The OSM data set to save … … 183 199 final JsonObjectBuilder propObj = Json.createObjectBuilder(); 184 200 for (Entry<String, String> t : p.getKeys().entrySet()) { 185 propObj.add(t.getKey(), t.getValue());201 propObj.add(t.getKey(), convertValueToJson(t.getValue())); 186 202 } 187 203 final JsonObject prop = propObj.build(); … … 199 215 .add("geometry", geom.isEmpty() ? JsonValue.NULL : geom)); 200 216 } 217 } 218 219 private static JsonValue convertValueToJson(String value) { 220 if (value.startsWith(JSON_VALUE_START_MARKER) && value.endsWith(JSON_VALUE_END_MARKER)) { 221 try (JsonParser parser = Json.createParser(new StringReader(value))) { 222 if (parser.hasNext() && parser.next() != null) { 223 return parser.getValue(); 224 } 225 } catch (JsonParsingException e) { 226 Logging.warn(e); 227 } 228 } 229 return Json.createValue(value); 201 230 } 202 231 -
trunk/test/unit/org/openstreetmap/josm/io/GeoJSONWriterTest.java
r16006 r16936 40 40 node.put("name", "foo"); 41 41 node.put("source", "code"); 42 node.put("data", "{\"foo\": 1, \"bar\": \"baz\"}"); 42 43 final DataSet ds = new DataSet(); 43 44 ds.addPrimitive(node); … … 52 53 " 'properties': {\n" + 53 54 " 'name': 'foo',\n" + 54 " 'source': 'code'\n" + 55 " 'source': 'code',\n" + 56 " 'data': {\n" + 57 " 'foo': 1,\n" + 58 " 'bar': 'baz'\n" + 59 " }\n" + 55 60 " },\n" + 56 61 " 'geometry': {\n" +
Note:
See TracChangeset
for help on using the changeset viewer.