Skip to content

Commit c8c1cbb

Browse files
fpanizzaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:fix/android-jsonwrapper' into beta
1 parent 08b3cc2 commit c8c1cbb

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

android/src/main/java/com/genexus/specific/android/AndroidJSONSerialization.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010

1111
public class AndroidJSONSerialization implements IExtensionJSONSerialization {
12+
1213
@Override
1314
public Iterator<Map.Entry<String, Object>> getJSONObjectIterator(JSONObjectWrapper obj) {
1415
Map<String, Object> map = new LinkedHashMap<>();
@@ -24,4 +25,15 @@ public Iterator<Map.Entry<String, Object>> getJSONObjectIterator(JSONObjectWrapp
2425
public JSONTokener getJSONTokener(String s) {
2526
return new AndroidJSONTokenerWrapper(s);
2627
}
28+
29+
@Override
30+
public Map<String, Object> getJSONObjectMap(JSONObjectWrapper obj) {
31+
Map<String, Object> map = new LinkedHashMap<>();
32+
for (Iterator<String> it = obj.keys(); it.hasNext(); ) {
33+
String k = it.next();
34+
map.put(k, obj.get(k)); // add key and value to map result
35+
}
36+
return map;
37+
38+
}
2739
}

common/src/main/java/com/genexus/common/interfaces/IExtensionJSONSerialization.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
public interface IExtensionJSONSerialization {
1010
Iterator<Map.Entry<String, Object>> getJSONObjectIterator(JSONObjectWrapper obj);
1111
JSONTokener getJSONTokener(String s);
12+
public Map<String, Object> getJSONObjectMap(JSONObjectWrapper obj);
1213
}

common/src/main/java/com/genexus/json/JSONObjectWrapper.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ public JSONObjectWrapper(String string) {
2222
? SpecificImplementation.JsonSerialization.getJSONTokener(string)
2323
: new JSONTokenerWrapper(string)
2424
);
25-
26-
if (map == null)
27-
map = new LinkedHashMap<String, Object>();
25+
initMap();
2826
}
2927

3028
public JSONObjectWrapper(JSONTokenerWrapper token) {
3129
super(token);
32-
if (map == null)
33-
map = new LinkedHashMap<String, Object>();
30+
initMap();
3431
}
3532

3633
public JSONObjectWrapper(Map<?,?> m) {
@@ -48,8 +45,18 @@ public JSONObjectWrapper(Map<?,?> m) {
4845

4946
public JSONObjectWrapper(JSONObject jsonObject) {
5047
super(jsonObject.toString());
48+
initMap();
49+
}
50+
51+
private void initMap() {
5152
if (map == null)
52-
map = new LinkedHashMap<String, Object>();
53+
{
54+
// this is a workaround for the Android implementation not loading the map in the JsonObject constructor
55+
if (SpecificImplementation.JsonSerialization != null)
56+
map = SpecificImplementation.JsonSerialization.getJSONObjectMap(this);
57+
else
58+
map = new LinkedHashMap<String, Object>();
59+
}
5360
}
5461

5562
public Set<Entry<String, Object>> entrySet() {

0 commit comments

Comments
 (0)