Skip to content

Commit

Permalink
3.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
miktim committed Jan 21, 2025
1 parent dfa8a5b commit 52d78af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ public class NamesOfNumbers extends HashMap<Double, String>
if (name.indexOf(':') < 0) { // first call without field name
// convert HashMap to Json object
Json j = new Json();
for (Double key : this.keySet().toArray(new Double[0])) {
j.put(key.toString(), this.get(key));
for (Map.Entry<Double,String> entry : this.entrySet()){
j.put(entry.getKey().toString(), entry.getValue());
}
// return newly created Json object
return new Json("HashMap", j);
Expand Down
Binary file not shown.
7 changes: 4 additions & 3 deletions src/org/miktim/json/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.LinkedHashMap;

public class Json extends LinkedHashMap<String, Object> {

// TODO: thread safe

public Json(InputStream inStream) throws IOException, ParseException {
super();
this.putAll((Json) JSON.fromJSON(inStream, "UTF-8"));
Expand Down Expand Up @@ -92,15 +93,15 @@ public Object put(String key, Object value) {

if (value != null) {
Class cls = value.getClass();
if (!cls.isPrimitive()) {
if (!(cls.isPrimitive() || cls == String.class)) {
try {
// TODO: something faster than a double conversion
// otherwise, it is a deep clone...
value = JSON.fromJSON(JSON.toJSON(value));
} catch (IOException | ParseException ex) {
}
}
}

return super.put(key == null ? "null" : key, value);
}

Expand Down

0 comments on commit 52d78af

Please sign in to comment.