function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Why is apex:form interfering with JSONGenerator?


I am trying to display an angularjs table and add some Visualforce + Apex filters to it. 
I am creating the JSON string in the Apex controller with 
JSONGenerator tableJson = JSON.createGenerator(true);
tableJson.writeStringField('name', 'value');
// etc

then format it for Visualforce to retrieve it:
public String getTableJson() {
        return tableJson.getAsString();

In Visualforce I can use angularjs ui-grid using this tableJson without problems
<div ng-app="report">
		<div ng-controller="MainCtrl">
			<div id="grid1" ui-grid-grouping="true" ui-grid="gridOptions" class="grid">

	<script type="text/javascript">
		var report = angular.module('report', ['ngTouch', 'ui.grid', 'ui.grid.grouping']);
		angular.module('report').factory('cellStyle', function(uiGridConstants, $http){
		  // cfg and $http together at last

		report.controller('MainCtrl', ['$scope', 'uiGridGroupingConstants', function ($scope, uiGridGroupingConstants) {
			$scope.gridOptions = {
				data: {!tableJson},
				onRegisterApi: function(gridApi) {
					$scope.gridApi = gridApi;

Everything is displaying perfectly.
However, if I add <apex:form> to the page (for the filters), I get this error:
System.JSONGenerator is not serializable. 

All I did was to add apex:form to the page, no content inside the form yet.
<div ng-app="report"><!-- content here --></div>
<script><!-- content here --></script>

and it stopped working. Does anyone have an idea why?

Many thanks!
Best Answer chosen by Sabina
Solved! :)  "When you use a form all of the non-transient data in your controller has to be serializable in order for us to store your view state." (
I marked my JSONGenerator tableJson as transient and it worked!

Leaving this here as that error message didn't return any Google results. Someone else might need it.