4

I'm comunicating with a web service via AutoBeans that are converted to JSON. The problem is that the web service expects every property of the JSON object to be present in the request whereas AutoBeanCodex.encode() seemingly leaves out all properties that have their default values (despite those being set explicitly).

Is there a way to include those properties too?

EDIT: Thomas' answer already helped a lot, but it still leaves a little problem. Namely an empty array (List<Integer> in my case) is swallowed as well, apparently because the default value there would be the empty array and not null.

Joey
  • 344,408
  • 85
  • 689
  • 683

1 Answers1

5

A workaround would probably be to use the wrapper types instead of the primitive ones, e.g. Boolean instead of boolean, Integer instead of int; that way, the default value would be null rather than false or 0.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks, in a way this should have been an obvious workaround. While I was busy thinking of ways to change that behaviour or even find the tiniest bit of documentation about it. – Joey Jul 26 '12 at 12:25
  • One minor problem remains, in that `List` will result in a left-out property too instead of an empty array. Any hint on that one? – Joey Jul 27 '12 at 11:32
  • Has anyone figured out a solution? I am having a similar issue with Date. I need json to have null for my date value. Thanks – Alexey Dec 13 '17 at 04:50