diff options
author | Anton Tananaev <anton@traccar.org> | 2022-11-02 17:57:22 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-11-02 17:57:22 -0700 |
commit | 9280355123ee13f7f7d8bf7076a39dcab57ab1cd (patch) | |
tree | e2cd820dc11d75048dd89c2b4ad54c8e5188da74 /src/main/java/org/traccar/model/ExtendedModel.java | |
parent | 49646eccd5ec57013c78ea0a0776c206f812cb0b (diff) | |
download | trackermap-server-9280355123ee13f7f7d8bf7076a39dcab57ab1cd.tar.gz trackermap-server-9280355123ee13f7f7d8bf7076a39dcab57ab1cd.tar.bz2 trackermap-server-9280355123ee13f7f7d8bf7076a39dcab57ab1cd.zip |
Improve attribute type handling
Diffstat (limited to 'src/main/java/org/traccar/model/ExtendedModel.java')
-rw-r--r-- | src/main/java/org/traccar/model/ExtendedModel.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index ef2e3b68f..7a61eda8c 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -91,7 +91,7 @@ public class ExtendedModel extends BaseModel { public String getString(String key) { if (attributes.containsKey(key)) { - return (String) attributes.get(key); + return attributes.get(key).toString(); } else { return null; } @@ -99,7 +99,12 @@ public class ExtendedModel extends BaseModel { public double getDouble(String key) { if (attributes.containsKey(key)) { - return ((Number) attributes.get(key)).doubleValue(); + Object value = attributes.get(key); + if (value instanceof Number) { + return ((Number) attributes.get(key)).doubleValue(); + } else { + return Double.parseDouble(value.toString()); + } } else { return 0.0; } @@ -107,7 +112,12 @@ public class ExtendedModel extends BaseModel { public boolean getBoolean(String key) { if (attributes.containsKey(key)) { - return (Boolean) attributes.get(key); + Object value = attributes.get(key); + if (value instanceof Boolean) { + return (Boolean) attributes.get(key); + } else { + return Boolean.parseBoolean(value.toString()); + } } else { return false; } @@ -115,7 +125,12 @@ public class ExtendedModel extends BaseModel { public int getInteger(String key) { if (attributes.containsKey(key)) { - return ((Number) attributes.get(key)).intValue(); + Object value = attributes.get(key); + if (value instanceof Number) { + return ((Number) attributes.get(key)).intValue(); + } else { + return Integer.parseInt(value.toString()); + } } else { return 0; } @@ -123,7 +138,12 @@ public class ExtendedModel extends BaseModel { public long getLong(String key) { if (attributes.containsKey(key)) { - return ((Number) attributes.get(key)).longValue(); + Object value = attributes.get(key); + if (value instanceof Number) { + return ((Number) attributes.get(key)).longValue(); + } else { + return Long.parseLong(value.toString()); + } } else { return 0; } |