{new} OpenAPI Parsers
The {@link oaj.oapi.OpenApiParser} class is used to convert HTTP parts back into POJOs.
The following is the previous example of a schema that defines the format of a pipe-delimited list of comma-delimited numbers (e.g.
The following code shows how the schema above can be used to parse our input into a POJO:
As a general rule, any POJO convertible from the intermediate type for the type/format of the schema can
be parsed using the OpenAPI parser.
Here are the rules of POJO types allowed for various type/format combinations:
| Type | Format | Valid parameter types |
|---|---|---|
string or empty |
byte |
|
date |
|
|
uon |
|
|
| empty |
|
|
boolean |
empty |
|
integer |
int32 |
|
int64 |
|
|
number |
float |
|
double |
|
|
array |
empty |
|
uon |
|
|
object |
empty |
|
uon |
|
For arrays, an example of "Any POJO transformable from arrays of the default types" is:
In the example above, our POJO class can be constructed from our pipe-delimited list of comma-delimited numbers:
Just like serialization, the object type is not officially part of the OpenAPI standard, but
Juneau supports parsing HTTP parts in UON notation to Maps and beans.
The following shows an example of a bean with several properties of various types.
We define the following schema again:
Then we parse our input into our POJO:
String input =
Note that serializing into generic Object properties would have produced similar results:
We can also parse into Maps as well:
String input =
ParseExceptions if you attempt an impossible conversion.
(e.g. trying to parse the string "foo" into a boolean).