Skip to content

Commit

Permalink
feat(remote): improve JSON handling of map objects in parameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Jun 30, 2024
1 parent c1932ec commit 3a4dadc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Maven Central dependency
<dependency>
<groupId>com.github.org-arl</groupId>
<artifactId>fjage</artifactId>
<version>1.12.3</version>
<version>1.13.0</version>
</dependency>

Contributing
Expand Down
16 changes: 16 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Release Notes

## v1.13.0

* Handle generic map objects in JSON serialization
* Javascript improvements

## v1.12.3

* Javascript improvements
* Improved darkmode support
* Improved handling of parameter change notifications
* Fix broken tests

## v1.12.2

* Gateway improvements

## v1.12.1

* Use LONG_OR_DOUBLE parsing for JSON
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.3
1.13.0
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
Expand Down Expand Up @@ -54,6 +56,11 @@ else if (List.class.isAssignableFrom(type) || (type.isArray() && type.getCompone
Object v = ((GenericValue)value).getValue();
delegate.write(out, v);
}
else if (Map.class.isAssignableFrom(type)) {
TypeAdapter delegate = gson.getAdapter(TypeToken.get(type));
Object v = ((GenericValue)value).getValue();
delegate.write(out, v);
}
else {
out.beginObject();
out.name("clazz").value(type.getName());
Expand Down Expand Up @@ -86,6 +93,7 @@ public T read(JsonReader in) throws IOException {
if (tok == JsonToken.BEGIN_OBJECT) {
TypeToken tt = null;
GenericValue rv = null;
Map<String,Object> map = new HashMap<String,Object>();
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
Expand All @@ -100,9 +108,28 @@ public T read(JsonReader in) throws IOException {
TypeAdapter delegate = gson.getAdapter(tt);
rv = new GenericValue(delegate.read(in));
}
else in.skipValue();
else {
JsonToken tok2 = in.peek();
if (tok2 == JsonToken.NULL) {
in.nextNull();
map.put(name, null);
}
else if (tok2 == JsonToken.NUMBER) {
String s = in.nextString();
try {
if (s.contains(".")) map.put(name, Double.parseDouble(s));
else map.put(name, Long.parseLong(s));
} catch (NumberFormatException ex) {
// ignore
}
}
else if (tok == JsonToken.STRING) map.put(name, in.nextString());
else if (tok == JsonToken.BOOLEAN) map.put(name, in.nextBoolean());
else in.skipValue();
}
}
in.endObject();
if (rv == null) rv = new GenericValue(map);
return (T)rv;
}
if (tok == JsonToken.BEGIN_ARRAY) {
Expand Down
2 changes: 1 addition & 1 deletion src/sphinx/fjage_quickstart.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# fjage version
VERSION=1.12.3
VERSION=1.13.0

# create the folder structure
mkdir -p build/libs etc logs samples
Expand Down

0 comments on commit 3a4dadc

Please sign in to comment.