Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Smartgwt and Jackson 2

    Hello,
    I am using SmartClient Version: SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
    with Chrome or Firefox.

    We communicate with our server using REST services and have recently upgraded our Jackson version to version 2 to take advantage of the @JsonIdentityInfo annotation for this reason:
    "Jackson 2.0 adds support for concept called "Object Identity":ability to serialize Object Id for values, use this id for secondary references; and ability to resolve these references when deserializing)"

    Using some test classes, an example of the output of this is as follows:

    Code:
    "{
        "@id": 1,
        "id": 2,
        "name":"testCategory",
        "activityList": [
            {
                "@id": 2,
                "id": 1,
                "name":"testActivity",
                "parentCategory": 1
            }
        ]
    }"
    The parentCategory in the activityList now has just a reference.

    Unfortunately when this gets to the Datasource I understandably get the following error:
    Code:
    java.lang.IllegalArgumentException: invoke arguments: JS value of type int, expected com.google.gwt.core.client.JavaScriptObject
    at
    com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178) 	at
    com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:65) 	at
    com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 	at
    com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338) 	at
    com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219) 	at
    com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 	at
    com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571) 	at
    com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279) 	at
    com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 	at
    com.google.gwt.core.client.impl.Impl.apply(Impl.java) 	at
    com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242) 	at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source) 	at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 	at
    java.lang.reflect.Method.invoke(Method.java:601) 	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 	at
    com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 	at
    com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 	at
    com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293) 	at
    com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547) 	at
    com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) 	at java.lang.Thread.run(Thread.java:722)
    Are there any plans to support Jackson 2 annotations in the future?
    Is there any way of telling smartgwt to use Jackson 2 for deseralising?

    Kind Regards,
    Jeni

    #2
    There shouldn't be any problem parsing the response you've shown. Probably you are actually getting the error from another response that actually has invalid values.

    We don't plan to add special support for Jackson or other JSON serialized. See the FAQ on why we don't recommend generated REST services - using Jackson to generate annotations instead of just JSON satisfying the RestDataSource protocol is not a direction we would suggest going in.

    Comment


      #3
      Hello, thank you for your quick response.
      We do format the json responses inline with the RestDataSource and example can be seen below
      Code:
       
      {
          "response":{
              "status":0,
              "startRow":0,
              "endRow":0,
              "totalRows":3,
              "invalidateCache":false,
              "errors":[],
              "data":[{
                  "@id":1,
                  "dateLastSearched":1357257600000,
                  "timesAppearedInSearch":0,
                  "timesAppearedInLists":0,
                  "id":3,
                  "categoryName":"Tennis",
                  "description":"Tennis activities",
                  "displayCategory":true,
                  "style":"#FFFF99",
                  "icon":null,
                  "parent":{
                      "@id":2,
                      "dateLastSearched":1357344000000,
                      "timesAppearedInSearch":0,
                      "timesAppearedInLists":0,
                      "id":101,
                      "categoryName":"Sports",
                      "description":"Sporting activities",
                      "displayCategory":true,
                      "style":null,
                      "icon":null,
                      "parent":null,
                      "children":[1,{
                          "@id":3,
                          "dateLastSearched":1357344000000,
                          "timesAppearedInSearch":0,
                          "timesAppearedInLists":0,
                          "id":103,
                          "categoryName":"Another One",
                          "description":"This is another category",
                          "displayCategory":true,
                          "style":null,
                          "icon":null,
                          "parent":2,
                          "children":[],
                          "activitiesList":[]
                      }],
                      "activitiesList":[]
                  },
                  "children":[]
                  },2,3]
              }
          }
      The problems occur where in this example the first object in the array is read fine and then because children of this object are also array entities jackson enters the @id number as the reference. This is therefore failing as an object is expected but an int is found.
      It is a shame but I guess we will have to manipulate the output further on the server with lazy loading etc to get the required results or transform the response.
      Thanks again,
      Kind Regards,
      Jeni

      Comment


        #4
        It's not the annotation properties as such, it's the mixed arrays of integers and objects that's the problem. It looks like Jackson is hoping to send a tree with identical nodes in different places, referring to nodes by ID when they recur.

        That concept - multiple nodes that are the same object - isn't currently supported by our Trees. So this isn't really a serialization issue as such, you just need to expand out your trees so we get a distinct object per node, and handle the mapping to stored objects as needed when data is saved.

        Comment

        Working...
        X