Serialize Java Objects in Embedded Forms

I have java class like this :slight_smile:

public class ReadJsonFile {
	Object jsonObjectData = new JSONObject();
	static JSONParser parser=new JSONParser();
public static void main(String args []) {
	readJson();
}

		
	
public static JSONArray readJson() {
	JSONArray json = null ;
	       try {
		         Object obj = parser.parse(new FileReader(
		                 "C:\\Users\\user\\Desktop\\service1\\camunda-test\\src\\main\\webapp\\forms\\data.json"));

		          json = (JSONArray) obj;

	            


		     } catch (Exception e) {
		         e.printStackTrace();
		     }
		return json;
	

}
} 

and i have embedded html form like this:

var holiDay = $scope.holiDay = [{}];
camForm.on('form-loaded', function() {

      // declare variable 'customerData' incuding metadata for serialization
      camForm.variableManager.createVariable({
        name: 'holiDay',
        type: 'Object',
        value: holiDay,
        valueInfo: {
          // indicate that object is serialized as json
          serializationDataFormat: 'application/json',
          // provide classname of java object
          objectTypeName: 'ge.psda.camunda.database.ReadJsonFile'
        }
      });

    });
console.log(holiDay.toString());
</script>

  <h3>Holiday Data</h3>

  <div class="control-group">
    <label class="control-label" for="holiDay">holiDay</label>
    <div class="controls">
      <input id="firstname"
             class="form-control"
             type="text"
             required 
             ng-model="holiDay.holidays">
    </div>
  
</form>

I HAVE USE THIS EXAMPLE TO SERIALIZE OBJECT: https://github.com/camunda/camunda-bpm-examples/tree/master/usertask/task-form-embedded-serialized-java-object
BUT WHEN I DEPLOY WAR INPUT IS EMPTY AND I CAN’T SEE any errors in console , what should i change to get this holiDay data into my mebedded form?

Hi @Sally,

I don’t understand your approach… Do you have a Java main class or a java delegate class where you want to read a JSON file and save the content of this in a process variable?

Please look again into the mentioned example: https://github.com/camunda/camunda-bpm-examples/tree/master/usertask/task-form-embedded-serialized-java-object

Cheers
kristin

Hi @kristin thank you for your reply, yes I have task listener(create) with this class ge.psda.camunda.database.ConnectToHoliDays