JSON.encode does only support "simple" objects per default. I.E. Map, List, String, num  and such.
Other objects must have a toJson method. Maybe this should be clarified.