Ticket #19632: 19632.1.patch
File 19632.1.patch, 4.3 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/io/GeoJSONReader.java
335 343 336 344 if (value instanceof JsonString) { 337 345 tags.put(stringJsonValueEntry.getKey(), ((JsonString) value).getString()); 338 } else if (value instanceof JsonObject ) {339 Logging.warn(340 "The GeoJSON contains an object with property '" + stringJsonValueEntry.getKey()341 + "' whose value has the unsupported type '" + value.getClass().getSimpleName()342 + "'. That key-value pair is ignored!"343 );346 } else if (value instanceof JsonObject || value instanceof JsonArray) { 347 /* When writing back to file, "{" and "}" are used to 348 * determine that it should be interpreted as a json 349 * object or array. They are stored in GeoJSONWriter as variables. */ 350 tags.put(stringJsonValueEntry.getKey(), GeoJSONWriter.JSON_VALUE_START_MARKER + value.toString() + 351 GeoJSONWriter.JSON_VALUE_END_MARKER); 344 352 } else if (value.getValueType() != JsonValue.ValueType.NULL) { 345 353 tags.put(stringJsonValueEntry.getKey(), value.toString()); 346 354 } -
src/org/openstreetmap/josm/io/GeoJSONWriter.java
1 1 // License: GPL. For details, see LICENSE file. 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; 6 7 import java.math.RoundingMode; … … 21 22 import javax.json.JsonValue; 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; 26 29 import org.openstreetmap.josm.data.coor.EastNorth; … … 54 57 private static final Set<Way> processedMultipolygonWays = new HashSet<>(); 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_END_MARKER} 62 * and {@link #JSON_VALUE_START_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_END_MARKER} 68 * and {@link #JSON_VALUE_START_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 59 75 * @since 12806 … … 182 198 // Properties 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(); 188 204 … … 200 216 } 201 217 } 202 218 219 private static JsonValue convertValueToJson(String value) { 220 if (value.startsWith(JSON_VALUE_START_MARKER) && value.endsWith(JSON_VALUE_END_MARKER)) { 221 // Trim the markers 222 String toParse = value.substring(1, value.length() - 2); 223 try (JsonParser parser = Json.createParser(new StringReader(toParse))) { 224 if (parser.hasNext() && parser.next() != null) 225 return parser.getValue(); 226 } catch (JsonParsingException e) { 227 Logging.trace(e); 228 } 229 } 230 return Json.createValue(value); 231 } 232 203 233 protected void appendLayerBounds(DataSet ds, JsonObjectBuilder object) { 204 234 if (ds != null) { 205 235 Iterator<Bounds> it = ds.getDataSourceBounds().iterator();