Changeset 16936 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-08-26T20:40:25+02:00 (4 years ago)
- File:
-
- 1 edited
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
Note:
See TracChangeset
for help on using the changeset viewer.