boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

Custom serializer for mixed data type #318

Open simonrenoult opened 9 years ago

simonrenoult commented 9 years ago

Hi there,

I would like to write a custom serializer for a JSON field that accepts mixed typed data as value (coercion). Here are two JSON samples {"foo": ["foo", "bar", "baz"]} and { "foo": "bar" }. Parsing such a JSON with a standard bean will obviously fail since a String won't be cast into an Array and vice versa.

class MyBean {
  private String foo; // Wil fail when an array is provided
}

class MyBean {
  private String[] foo; // Wil fail when a string is provided
}

How can this be achieved with Boon ?

I'll appreciate any help ! Thanks :)

RichardHightower commented 9 years ago

that is a tough one. No easy way to do this with boon. At this point.