This is a migrated thread and some comments may be shown as answers.

"Input string is not well formed JSON" exception when deleting row

0 Answers 806 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 23 Nov 2012, 10:53 AM
Hello,

I try to combine Kendo UI with Struts 2 action. Until now the results to retrieve data from the DB are satisfactory.
The table is loaded correctly with the data retrieved from the Action.  The problem starts when i try to delete
an entry. 

Source code:

<script>
              $(document).ready(function () {
 
                  var crudServiceBaseUrl = "http://demos.kendoui.com/service",
                      dataSource = new kendo.data.DataSource({
                          transport: {
                              read:  {
                     url: "http://localhost:8080/ProjectRoot/myProject,
                                  dataType: "json"
                              },                         
                              destroy: {
                                  url: "http://localhost:8080/ProjectRoot/myProject!deleteRow",
                                  dataType: "jsonp",
                                  contentType: "application/json; charset=utf-8"
                              },
                              parameterMap: function(options, operation) {
                                  if (operation !== "read" && options.models) {
                                      return {models: kendo.stringify(options.models)};
                                  }
                              }
                          },
                          batch: true,
 
                          pageSize: 30,
                          schema: {
 
                              data: "myList",
                              model: {
                                  id: "uuid",
 
                                  fields: {
                             
                                      uuid: { editable: false, nullable: true },
                                      lang: { type: "string" },
                                      text: { type: "string" }
 
                                  }
                              }
                          }
                      });
 
                  $("#grid").kendoGrid({
                      dataSource: dataSource,
                      pageable: true,
                      height: 400,
                      toolbar: ["create"],
                      columns: [
                          { field:"lang", title: "Language" },
                          { field: "text", title:"Text", width: "150px" },
                          { command: ["edit", "destroy"], title: " ", width: "210px" }],
                      editable: "popup"
                  });
              });
          </script>


Inside my Struts 2 action i have getters and setters for the following variables:
-String text;
-String lang;
-String models;

Now i noticed the following behaviour:

First Scenario

When calling the deleteRow function in my struts action, the following parameters are send of the current row that i want to delete:
callback jQuery17201980517354870166_1353667373995
models [{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"},{"lang":"de","text":"Stephan","uuid":"46baf7b1-2345-11e2-81c1-0800200c9a66"}]

This is a copy of the url parameters: _=1353667421178
callback=jQuery17201980517354870166_1353667373995
models=[{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"},{"lang":"de","text":"Stephan","uuid":"46baf7b1-2345-11e2-81c1-0800200c9a66"}]

Unfortunately as a response from the server i get the following error :
org.apache.struts2.json.JSONException: Input string is not well formed JSON (invalid char ?)
    org.apache.struts2.json.JSONReader.buildInvalidInputException(JSONReader.java:155)

I did a debugging on the JSONInterceptor and found out that the json variable when trying to do the deserialize
Object obj = JSONUtil.deserialize(request.getReader());
the json variable is an empty string. Thus the above error.


Second Scenario

Instead of calling a function to delete, i changed that to call an action. When doing this, the action
is called and my String models variable is set with the following values [{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"}].

This seems sort of correct. Unfortunately with this case, the whole process does not go through the
JSONInterceptor, so no deserialization is happening.



So what is my goal:
To be able when pressing on delete to call the delete function and set the object with the values that are
sent from kendo in order to continue with my own business logic process. What could be wrong
in my first scenario ?

Please let me know if you need further information.

Regards

Stephan



No answers yet. Maybe you can help?

Tags
Grid
Asked by
Stephan
Top achievements
Rank 1
Share this question
or