Friday, July 10, 2020

Re: Problem decoding complex AutoBean

Can anyone help me?
My json string is - 
{
"themeId": 1,
"name": "rpc",
"enabled": true,
"propertiesList": [
{
"id": 1,
"themeConfigurationId": 1,
"chatScreen": "chatScreen",
"component": "header",
"property": "text",
"value": "HELLO"
},
{
"id": 3,
"themeConfigurationId": 1,
"chatScreen": "chatScreen",
"component": "background",
"property": "color",
"value": "rgba(0,191,255,0.5)"
}
]
}

Interfaces are -

public interface IWebchatThemeConfigurationBean { public Integer getThemeId(); public String getName(); public Boolean getEnabled(); public List<IWebchatThemeConfigurationPropertyBean> getPropertiesList(); }
public interface IWebchatThemeConfigurationPropertyBean { public Integer getId(); public Integer getThemeConfigurationId(); public String getChatScreen(); public String getComponent(); public String getProperty(); public String getValue(); }

public interface ChatFactory extends AutoBeanFactory {
        AutoBean<IWebchatThemeConfigurationBean> theme();

        AutoBean<IWebchatThemeConfigurationPropertyBean> properties();
    }
    ChatFactory factory;
factory = GWT.create(ChatFactory.class);

IWebchatThemeConfigurationBean deserializeFromJson(String json) { AutoBean<IWebchatThemeConfigurationBean> bean = AutoBeanCodex.decode(factory, IWebchatThemeConfigurationBean.class, json); return bean.as(); }

in this returned bean I'm getting null propertiesList.
name, enabled, themeId are fine.

On Tuesday, August 20, 2013 at 8:07:30 AM UTC+5:30, Thad Humphries wrote:
I've managed a simple AutoBean with a list. Now I've a more complex one, and I don't understand what's wrong. My get methods are returning null though the debugger shows the object has data.

The JSON looks like this:

{
  "mquery":
    {
      "screenname":"Index Card",
      "fields":
        {
          "field":[
            {"title":"Name",  "name":"odname",   "value":"*TIFF*"},
            {"title":"Date",  "name":"oddate",   "value":""},
            {"title":"Ref #", "name":"odrefnum", "value":""}
          ]
        }
    }


I have three interfaces:

public interface Field {
  String getTitle();
  void setTitle(String title);
  String getName();
  void setName(String name);
  String getValue();
  void setValue(String value);
}

public interface FieldList {
  List<Field> getField();
  void setField(List<Field> field);
}

public interface MQuery {
  String getScreenname();
  void setScreenname(String screenname);
  FieldList getFields();
  void setFields(FieldList fields);
}

In my bean factory, I have

public interface BeanFactory extends AutoBeanFactory {
  ...
  AutoBean<Field> field();
  AutoBean<FieldList> fields();
  AutoBean<MQuery> mquery();
}

In my onResponseReceived() method, I call

  AutoBean<MQuery> mqueryBean = 
      AutoBeanCodex.decode(clientFactory.getBeanFactory()
          MQuery.class, response.getText());
  MQuery mQuery = mqueryBean.as();
  logger.log(Level.INFO, mQuery.getScreenname());
  screenName = mQuery.getScreenname();
  fieldList = mQuery.getFields().getField();
  view.renderFields(fieldList);

When I look at the debugger in Chrome, screenname, etc are populated (in mQuery:this$0:data_0 there is mquery with screenename set and 3 field objects in fields). However mQuery.getScreenname() returns null as does mQuery.getFields().

What am I not seeing here? Could the presence of other AutoBean<>s in my factory (beans that work) be messing me up (do I need a separate factory)?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/9aaf50f4-7464-4498-8632-701e4fd217f5o%40googlegroups.com.

No comments:

Post a Comment