Skip to content

Commit

Permalink
Fix for issue UiPath#31 on empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
alcxs committed Nov 25, 2020
1 parent 08a8bfb commit d87ac46
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
################################################################################

/.vs
/Activities/Java/Invoke/out
Binary file modified Activities/Java/Invoke/artifacts/InvokeJava.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class ArrayTypeSerializer implements TypeSerializerInterface {

public JavaObject DeserializeToJavaObject(JSONObject obj) {
JSONArray array = null;
String runtimeArrayType = null;
try {
array = obj.getJSONArray("value");
runtimeArrayType = obj.getString("runtime_arrayType");
}
catch (JSONException e) { }

Expand All @@ -29,6 +31,9 @@ public JavaObject DeserializeToJavaObject(JSONObject obj) {
}
Class<?> arrayType = getArrayType(context, array);
int length = array.length();
if (array.length() == 0){
return EmptyTypeSerializer.DeserializeToJavaObject(runtimeArrayType);
}
Object result = Array.newInstance(arrayType, length);

for (int i = 0; i < length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@
import com.uipath.instance.ObjectInstance;
import org.json.JSONObject;

import java.lang.reflect.Array;

public class EmptyTypeSerializer implements TypeSerializerInterface {

public JavaObject DeserializeToJavaObject(JSONObject obj) {
return new JavaObject(new EmptyClass(), EmptyClass.class);
}

public static JavaObject DeserializeToJavaObject(String type){
if ("System.Int32[]".equals(type)) {
return new JavaObject(new int[0], Array.newInstance(int.class, 0).getClass());
} else if ("System.Boolean[]".equals(type)) {
return new JavaObject(new boolean[0], Array.newInstance(boolean.class, 0).getClass());
} else if ("System.Byte[]".equals(type)) {
return new JavaObject(new byte[0], Array.newInstance(byte.class, 0).getClass());
} else if ("System.Char[]".equals(type)) {
return new JavaObject(new char[0], Array.newInstance(char.class, 0).getClass());
} else if ("System.Double[]".equals(type)) {
return new JavaObject(new double[0], Array.newInstance(double.class, 0).getClass());
} else if ("System.Single[]".equals(type)) {
return new JavaObject(new float[0], Array.newInstance(float.class, 0).getClass());
} else if ("System.Int64[]".equals(type)) {
return new JavaObject(new long[0], Array.newInstance(long.class, 0).getClass());
} else if ("System.String[]".equals(type)) {
return new JavaObject(new String[0], Array.newInstance(String.class, 0).getClass());
} else if ("System.Int16[]".equals(type)) {
return new JavaObject(new short[0], Array.newInstance(short.class, 0).getClass());
}
return new JavaObject(new Object[0], Array.newInstance(Object.class, 0).getClass());
}

public JSONObject SerializeToDotNet(ObjectInstance obj) {
return new JSONObject();
}
Expand Down
4 changes: 4 additions & 0 deletions Activities/Java/UiPath.Java/Service/JavaObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public object Value
[DataMember(Name = "runtime_type", EmitDefaultValue = false)]
public string RunTimeType { get; set; }

[DataMember(Name = "runtime_arrayType", EmitDefaultValue = false)]
public string RunTimeArrayType { get; set; }

[DataMember(Name = "reference_id", EmitDefaultValue = false)]
public string ReferenceId { get; set; }

Expand Down Expand Up @@ -68,6 +71,7 @@ private void SetValue(object value)
}
}).ToList();
RunTimeType = "Array";
RunTimeArrayType = value?.GetType()?.ToString();
}
else
{
Expand Down

0 comments on commit d87ac46

Please sign in to comment.