Support for List and Map

It can't be done inside `generateElementWriteCode` because that code needs to be called recursively and the optional part only applies to the whole field at the top level.