As JSON is a text-based format, associating binary data (such as file content) inside a JSON document directly is not technically feasible. Therefore, a text representation for the binary data should be used in order to be shown in the resulting JSON as an alternative to the direct bytes array.
JSON-B supports three different strategies to represent the bytes array in JSON documents:
- Binary: Using this strategy, binary data is encoded as a byte array.
- Base 64: Using this strategy, binary data is encoded using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045.
- Base 64 URL: Using this strategy, binary data is encoded using the URL and Filename safe Base64 Alphabet as specified in Table 2 of RFC 4648. This is compliant with the Internet JSON (I-JSON) profile.
For example, let's define a movie
object, with a binary array representing its thumbnail, and load the binary data from a file, as shown in the following example:
public class Movie { private long id; private...