Anvil serializable across server to front-end

I thought I would test and convert non-serialiazable value before being passed back to the front-end.

This one liner does quite a lot. The function ensure_anvil_serialiazable(item) test wether anvil will be ok with the value. At this stage, it prints out the type of the item and simply return the item.

      result = [{indx: {"value": ensure_anvil_serializable(x[indx].toPython()), "type": str(type(x[indx]))} for indx in x.labels} for x in res]

When I return result, I get the message

anvil.server.SerializationError: Cannot serialize return value from function. You can only pass strings, numbers, arrays, lists, LiveObjects and Media to or from server functions

Any ideas how to fix this?

All is fine. The function was working, but different test data caused this problem.

I’m curious. Where did you find this function?

HaHa - I’m writing my own to ensure that I can control the way in which Python objects are returned.

1 Like