public byte [] writeDocument(JSONAPIDocument<?> document, SerializationSettings settings)
			throws DocumentSerializationException {
		try {
			resourceCache.init();

			Map<String, ObjectNode> includedDataMap = new HashMap<>();

			ObjectNode result = objectMapper.createObjectNode();

			// Serialize data if present
			if (document.get() != null) {
				ObjectNode dataNode = getDataNode(document.get(), includedDataMap, settings);
				result.set(DATA, dataNode);

				// It is possible that relationships point back to top-level resource, in this case remove it from
				// included section since it is already present (as a top level resource)
				String identifier = String.valueOf(getIdValue(document.get()))
						.concat(configuration.getTypeName(document.get().getClass()));
				includedDataMap.remove(identifier);
				result = addIncludedSection(result, includedDataMap);
			}

			// Serialize errors if present
			if (document.getErrors() != null) {
				ArrayNode errorsNode = objectMapper.createArrayNode();
				for (Error error : document.getErrors()) {
					errorsNode.add(objectMapper.valueToTree(error));
				}

				result.set(ERRORS, errorsNode);
			}

			// Serialize global links and meta
			serializeMeta(document, result, settings);
			serializeLinks(document, result, settings);
			return objectMapper.writeValueAsBytes(result);
		} catch (Exception e) {
			throw new DocumentSerializationException(e);
		} finally {
			resourceCache.clear();
		}
	}
public byte [ ] writeDocument ( JSONAPIDocument < ? > document , SerializationSettings settings ) throws DocumentSerializationException { try { resourceCache . init ( ) ; Map < String , ObjectNode > includedDataMap = new HashMap < > ( ) ; ObjectNode result = objectMapper . createObjectNode ( ) ; if ( document . get ( ) != null ) { ObjectNode dataNode = getDataNode ( document . get ( ) , includedDataMap , settings ) ; result . set ( DATA , dataNode ) ; String identifier = String . valueOf ( getIdValue ( document . get ( ) ) ) . concat ( configuration . getTypeName ( document . get ( ) . getClass ( ) ) ) ; includedDataMap . remove ( identifier ) ; result = addIncludedSection ( result , includedDataMap ) ; } if ( document . getErrors ( ) != null ) { ArrayNode errorsNode = objectMapper . createArrayNode ( ) ; for ( Error error : document . getErrors ( ) ) { errorsNode . add ( objectMapper . valueToTree ( error ) ) ; } result . set ( ERRORS , errorsNode ) ; } serializeMeta ( document , result , settings ) ; serializeLinks ( document , result , settings ) ; return objectMapper . writeValueAsBytes ( result ) ; } catch ( Exception e ) { throw new DocumentSerializationException ( e ) ; } finally { resourceCache . clear ( ) ; } }
Serializes provided {@link JSONAPIDocument} into JSON API Spec compatible byte representation.

@param document {@link JSONAPIDocument} document to serialize
@param settings {@link SerializationSettings} settings that override global serialization settings
@return serialized content in bytes
@throws DocumentSerializationException thrown in case serialization fails