Menu

DefaultValueProcessor

Help
wbrian
2008-03-26
2013-04-29
  • wbrian

    wbrian - 2008-03-26

    hi there,

    I'm converting a json string request object into a pojpo;
    one of the properties of the pojo is an enum; the EnumMorpher
    and the conversion works fine so long as the value of the corresponding property
    in the json object is one of the expected enum values.

    there are occasions where the corresponding json property is "";
    what I'd like is to create the pojo with the enum property = null
    is such circumstances. I tried using a DefaultValueProcessor but the resultant
    bean was null.

    without some way of handling the json property with value of "" the error generated is: "Error while setting property=iconName type class".

    IconName is the name of the enum.
    jsonRequest is the name of the json string request object

    The converter class is as follows:
    ....
    JSONUtils.getMorpherRegistry().registerMorpher(new EnumMorpher(IconName.class));
                
    ....
    JSONObject jsonObject = JSONObject.fromObject(jsonRequest);

    ....
    Class x =  marker.html.HtmlUtil.IconName.class;
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerDefaultValueProcessor(marker.html.HtmlUtil.IconName.class,
        new  DefaultValueProcessor () {
            public Object getDefaultValue(Class x) {
                return null;
        });

    returnBean = (T) JSONObject.toBean(jsonObject, jsonConfig );

    ...

    the returnBean is null;

    below, requestBean is the json string request object.
    the call to the Converter class is:
            Converter<CorrectionRequestBean> abf = new Converter<CorrectionRequestBean>();
            CorrectionRequestBean cRequestBean = abf.createRequestBean(CorrectionRequestBean.class, requestBean);

    the error at the above line is:
    java.lang.ClassCastException: net.sf.ezmorph.bean.MorphDynaBean

    any assistance you may provide would be greatly appreciated,
    Brian

     
    • aalmiray

      aalmiray - 2008-04-03

      Hi Brian,

      I'm sorry for not replying earlier, could you send me a failing testcase?

      Thanks,
      Andres

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.