'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Type TestType(t1 As String, t2 As Int, t3 As Boolean, t4 As Double)
End Sub
Sub AppStart (Args() As String)
Dim t As TestType
t.Initialize
t.t1 = "Test"
t.t2 = 5
t.t3 = False
t.t4 = cPI
LogMap(ObjectToMap(t),False,"")
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub ObjectToMap(o As Object) As Map
Dim primitives As List = Array As String("java.lang.String","java.lang.Integer","java.lang.Boolean","java.lang.Long", _
"java.lang.Short","java.lang.Char","java.lang.Float","java.lang.Double")
Dim m As Map
m.Initialize
m.Put("JavaType",GetType(o))
If primitives.IndexOf(GetType(o))>-1 Then
m.Put("value",o)
Return m
End If
Dim r As Reflector
r.Target = o
Dim jo As JavaObject = Me
Dim fields() As String = jo.RunMethod("GetFields", Array(o))
For Each f As String In fields
m.Put(f,ObjectToMap(r.GetField(f)))
Next
Return m
End Sub
'Handy little sub
Public Sub LogMap(m As Map, saveToFile As Boolean, fileName As String)
Dim jg As JSONGenerator
jg.Initialize(m)
Log(jg.ToPrettyString(3))
If saveToFile Then File.WriteString(File.DirApp, fileName, jg.ToPrettyString(3))
End Sub
#If JAVA
import java.lang.reflect.Field;
public static String[] GetFields(Object o)
{
Class oc = o.getClass();
Field[] fields = oc.getDeclaredFields();
String[] res = new String[fields.length] ;
for(int j=0;j<fields.length;j++)
{
res[j] = fields[j].getName();
}
return res;
}
#End If