My XML
<Parent>
<childs>
<child>1</child>
<child>0</child>
</childs>
</Parent>
Pojo Structure is
class Parent
{
@JacksonXmlElementWrapper(localName = "childs")
ArrayList<Child> childs;
}
class Child
{
@JacksonXmlProperty(localName = "child")
boolean child;
}
Now as per my understanding, Jackson should convert this value 1/0 to boolean
. But since Jackson is assuming it as String
, I am getting this error:
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type boolean from String "1": only "true"/"True"/"TRUE" or "false"/"False"/"FALSE" recognized
I know this can be solved using custom deserialization, but I'm looking for a cleaner solution.
Other Tried Solutions:
@JsonFormat(shape = JsonFormat.Shape.STRING) private int chlid;
//Didn't work- CoercionConfig //Didn't work
- @JsonCreator with constructor and string as parameter //Worked but not feasible to write unused constructor in every class
My XMLMapper
this.mXmlMapper = new XmlMapper();
this.mXmlMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
this.mXmlMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
this.mXmlMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
this.mXmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
Same issue is for int
variables, error stating String
cannot be converted to int
.
Using this in Android for project.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745058902a4608841.html
评论列表(0条)