Ignore:
Timestamp:
2015-05-10T13:27:54+02:00 (9 years ago)
Author:
bastiK
Message:

applied #10454 - Mapbox "empty" tile (imagery with zoom level > 17) (patch by wiktorn)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r8339 r8344  
    1414import java.io.PrintWriter;
    1515import java.io.Reader;
     16import java.io.StringReader;
     17import java.io.StringWriter;
    1618import java.lang.annotation.Retention;
    1719import java.lang.annotation.RetentionPolicy;
     
    2224import java.util.Collection;
    2325import java.util.Collections;
     26import java.util.HashMap;
    2427import java.util.HashSet;
    2528import java.util.Iterator;
     
    3841import java.util.regex.Pattern;
    3942
     43import javax.json.Json;
     44import javax.json.JsonObject;
     45import javax.json.JsonObjectBuilder;
     46import javax.json.JsonReader;
     47import javax.json.JsonValue;
     48import javax.json.JsonWriter;
    4049import javax.swing.JOptionPane;
    4150import javax.swing.UIManager;
     
    12661275    }
    12671276
     1277    @SuppressWarnings("rawtypes")
     1278    private static String mapToJson(Map map) {
     1279        StringWriter stringWriter = new StringWriter();
     1280        try (JsonWriter writer = Json.createWriter(stringWriter)) {
     1281            JsonObjectBuilder object = Json.createObjectBuilder();
     1282            for(Object o: map.entrySet()) {
     1283                Entry e = (Entry) o;
     1284                object.add(e.getKey().toString(), e.getValue().toString());
     1285            }
     1286            writer.writeObject(object.build());
     1287        }
     1288        return stringWriter.toString();
     1289    }
     1290
     1291    @SuppressWarnings({ "rawtypes", "unchecked" })
     1292    private static Map mapFromJson(String s) {
     1293        Map ret = null;
     1294        try (JsonReader reader = Json.createReader(new StringReader(s))) {
     1295            JsonObject object = reader.readObject();
     1296            ret = new HashMap(object.size());
     1297            for (Entry<String, JsonValue> e: object.entrySet()) {
     1298                ret.put(e.getKey(), e.getValue().toString());
     1299            }
     1300        }
     1301        return ret;
     1302    }
     1303
    12681304    public static <T> Map<String,String> serializeStruct(T struct, Class<T> klass) {
    12691305        T structPrototype;
     
    12851321                if (fieldValue != null) {
    12861322                    if (f.getAnnotation(writeExplicitly.class) != null || !Objects.equals(fieldValue, defaultFieldValue)) {
    1287                         hash.put(f.getName().replace("_", "-"), fieldValue.toString());
     1323                        String key = f.getName().replace("_", "-");
     1324                        if (fieldValue instanceof Map) {
     1325                            hash.put(key, mapToJson((Map) fieldValue));
     1326                        } else {
     1327                            hash.put(key, fieldValue.toString());
     1328                        }
    12881329                    }
    12891330                }
     
    13321373            } else  if (f.getType() == String.class) {
    13331374                value = key_value.getValue();
    1334             } else
     1375            } else if (f.getType().isAssignableFrom(Map.class)) {
     1376                value = mapFromJson(key_value.getValue());
     1377            }
     1378            else
    13351379                throw new RuntimeException("unsupported preference primitive type");
    13361380
Note: See TracChangeset for help on using the changeset viewer.