Changeset 16645 in josm
- Timestamp:
- 2020-06-14T22:59:08+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/StructUtils.java
r16589 r16645 35 35 import org.openstreetmap.josm.tools.MultiMap; 36 36 import org.openstreetmap.josm.tools.ReflectionUtils; 37 import org.openstreetmap.josm.tools.StringParser; 37 38 import org.openstreetmap.josm.tools.Utils; 38 39 … … 45 46 */ 46 47 public final class StructUtils { 48 49 private static final StringParser STRING_PARSER = new StringParser(StringParser.DEFAULT) 50 .registerParser(Map.class, StructUtils::mapFromJson) 51 .registerParser(MultiMap.class, StructUtils::multiMapFromJson); 47 52 48 53 private StructUtils() { … … 221 226 } 222 227 for (Map.Entry<String, String> keyValue : hash.entrySet()) { 223 Object value;224 228 Field f = getDeclaredFieldInClassOrSuperTypes(klass, keyValue.getKey().replace('-', '_')); 225 229 … … 228 232 } 229 233 ReflectionUtils.setObjectsAccessible(f); 230 if (f.getType() == Boolean.class || f.getType() == boolean.class) { 231 value = Boolean.valueOf(keyValue.getValue()); 232 } else if (f.getType() == Integer.class || f.getType() == int.class) { 233 try { 234 value = Integer.valueOf(keyValue.getValue()); 235 } catch (NumberFormatException nfe) { 236 continue; 237 } 238 } else if (f.getType() == Double.class || f.getType() == double.class) { 239 try { 240 value = Double.valueOf(keyValue.getValue()); 241 } catch (NumberFormatException nfe) { 242 continue; 243 } 244 } else if (f.getType() == String.class) { 245 value = keyValue.getValue(); 246 } else if (f.getType().isAssignableFrom(Map.class)) { 247 value = mapFromJson(keyValue.getValue()); 248 } else if (f.getType().isAssignableFrom(MultiMap.class)) { 249 value = multiMapFromJson(keyValue.getValue()); 250 } else 251 throw new JosmRuntimeException("unsupported preference primitive type"); 252 234 Object value = STRING_PARSER.parse(f.getType(), keyValue.getValue()); 253 235 try { 254 236 f.set(struct, value);
Note:
See TracChangeset
for help on using the changeset viewer.