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));
....
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;
});
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Hi Brian,
I'm sorry for not replying earlier, could you send me a failing testcase?
Thanks,
Andres