java – How to enforce type of variable when converting from XML to JSON using BeanIO template?

I am using 2.1.0 version of BeanIO. I have multiple fields of int, and string types. I want to enforce those fields inside converted JSON file. I have already defined types for each of my field, but I have few fields where they have a number but they need to be stored as a string and few fields that need to be stored as ints. How do I enforce that inside my JSON file?

I added all of those fields inside a list but it does not get recognized as a list unless I add 2 elements inside it after converting from XML to JSON. How do I make sure that it be recognized as list even if it only has 1 element inside of it instead of 2?

I have added types to each of my field, but they are not being enforced after I convert from XML to JSON. I have tried doing JSONObject json = XML.toJSONObject(str, true); when converting from XML to JSON but it converts all fields into string which I do not want as I want some of the fields with numerical value to be stored as int and some of them to be stored as string.

Thanks for all the help.

Read more here: Source link