POJO Categories
In general, Juneau allows for marshalling for a wide variety of POJO types including:
The following chart shows POJOs categorized into groups and whether they can be serialized or parsed:
General POJO serialization/parsing support
| Group | Description | Examples | Can serialize? | Can parse? |
|---|---|---|---|---|
| 1 | Java primitives and primitive objects |
| yes | yes |
| 2 | Java Collections Framework objects, Java arrays, Java Optionals | å | ||
| 2a | With standard keys/values |
| yes | yes |
| 2b | With non-standard keys/values |
| yes | no |
| 3 | Java Beans | |||
| 3a | With standard properties | yes | yes | |
| 3b | With non-standard properties or not true beans | yes | no | |
| 3c | Virtual beans | yes | yes | |
| 3d | Read-only beans without setters | yes | no | |
| 4 | Swapped objects | |||
| 4a | 2-way swapped to group [1, 2a, 3ac] objects |
| yes | yes |
| 4b | 1-way swapped to group [1, 2, 3] objects |
| yes | no |
| 5 |
|
| yes | no |
| 6 | Non-serializable objects with standard methods for converting to a serializable form | |||
| 6a | Classes with a method that converts it to a serializable form:
And a method that converts it back into the original object:
|
| yes | yes |
| 6b | Classes that only have a method to convert to a serializable form:
| yes | no | |
| 7 | All other objects | yes | no |
Serializers are designed to work on tree-shaped POJO models.
These are models where there are no referential loops (e.g. leaves with references to nodes, or nodes in one branch
referencing nodes in another branch).
There is a serializer setting detectRecursions to look for and handle these kinds of loops (by setting these
references to null) but it is not enabled by default since it introduces a moderate performance penalty.
POJOs convertible to/from Strings
A separate category exists for POJOs that can be converted to and from Strings. These are used in places such as:
- Serializing of POJOs to Strings in the REST client API when no serializers are registered.
- Parsing of POJOs from Strings in the REST server API for
text/plainrequests wheretext/plainis not already mapped to an existing serializer.
As a general rule, all POJOs are converted to Strings using the toString() method.
However, there is one exception:
POJOs are convertible from Strings using any of the following (matched in the specified order):
- Any of the following public static non-deprecated methods:
create(String)fromString(String)fromValue(String)valueOf(String)parse(String)parseString(String)forName(String)forString(String)
- Has a public constructor that takes in a
String.
Exceptions exist for the following classes:
_ with -."null" are interpreted as null values.void.class) - Uses the primitive wrapper classes for instantiating from Strings.POJOs convertible to/from other types
POJOs are also converted to various other types in places such as the Open-API serializers and parsers.
In this section, the type being converted to will be referred to as X.
POJOs are considered convertible from X if it has any of the following (matched in the specified order):
- Any any of the following public static non-deprecated methods:
create(X)from*(X)
- Has a public constructor that takes in an
X. - The X class has a public non-static no-arg non-deprecated method called
to*().
POJOs are considered convertible from X if any of the reverse of above are true.
Share feedback or follow-up questions for this page directly through GitHub.