Class JsonApiDocumentWriter

java.lang.Object
com.kazforge.jsonapi.jackson3.JsonApiDocumentWriter

public final class JsonApiDocumentWriter extends Object
Validates a JsonApiDocument against a bound ValidationContext, then writes it with deterministic JSON:API v1.1 wire semantics.

Aggregate validation always runs before generator output starts, so validation failure cannot leave a partially written document.

Writing a MappedDocument is provenance-aware: this writer composes its bound context with the mapping's sparse-fieldset linkage exemptions before validation, so callers never translate mapping provenance into validation policy themselves. Every other bound setting is preserved; an empty exemption set validates exactly like plain document writing. All output forms share one composition path.

Caller-provided OutputStream and Writer sinks remain caller-owned and are never closed. The caller owns the buffering and flushing lifecycle of layers it supplies.

  • Method Summary

    Modifier and Type
    Method
    Description
    com.kazforge.jsonapi.core.aggregate.ValidationContext
    Validation context bound to this writer (before mapped-document provenance composition).
    void
    writeValue(OutputStream out, com.kazforge.jsonapi.core.model.JsonApiDocument document)
    Validates document against the bound context, then writes it to out.
    void
    writeValue(OutputStream out, com.kazforge.jsonapi.mapping.MappedDocument mapped)
    Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it to out.
    void
    writeValue(Writer out, com.kazforge.jsonapi.core.model.JsonApiDocument document)
    Validates document against the bound context, then writes it to out.
    void
    writeValue(Writer out, com.kazforge.jsonapi.mapping.MappedDocument mapped)
    Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it to out.
    void
    writeValue(tools.jackson.core.JsonGenerator generator, com.kazforge.jsonapi.core.model.JsonApiDocument document)
    Validates document against the bound context, then writes it through generator.
    void
    writeValue(tools.jackson.core.JsonGenerator generator, com.kazforge.jsonapi.mapping.MappedDocument mapped)
    Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it through generator.
    byte[]
    writeValueAsBytes(com.kazforge.jsonapi.core.model.JsonApiDocument document)
    Validates a plain document against the bound context, then returns its UTF-8 JSON bytes.
    byte[]
    writeValueAsBytes(com.kazforge.jsonapi.mapping.MappedDocument mapped)
    Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then returns the UTF-8 JSON bytes.
    writeValueAsString(com.kazforge.jsonapi.core.model.JsonApiDocument document)
    Validates a plain document against the bound context, then returns its JSON string.
    writeValueAsString(com.kazforge.jsonapi.mapping.MappedDocument mapped)
    Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then returns the JSON string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • context

      public com.kazforge.jsonapi.core.aggregate.ValidationContext context()
      Validation context bound to this writer (before mapped-document provenance composition).
    • writeValueAsString

      public String writeValueAsString(com.kazforge.jsonapi.core.model.JsonApiDocument document)
      Validates a plain document against the bound context, then returns its JSON string.
    • writeValueAsBytes

      public byte[] writeValueAsBytes(com.kazforge.jsonapi.core.model.JsonApiDocument document)
      Validates a plain document against the bound context, then returns its UTF-8 JSON bytes.
    • writeValue

      public void writeValue(OutputStream out, com.kazforge.jsonapi.core.model.JsonApiDocument document)
      Validates document against the bound context, then writes it to out. The stream remains caller-owned and is not closed; the caller owns its buffering and flushing lifecycle. Only the generator created for this call is closed.
    • writeValue

      public void writeValue(Writer out, com.kazforge.jsonapi.core.model.JsonApiDocument document)
      Validates document against the bound context, then writes it to out. The writer remains caller-owned and is not closed; the caller owns its buffering and flushing lifecycle. Only the generator created for this call is closed.
    • writeValue

      public void writeValue(tools.jackson.core.JsonGenerator generator, com.kazforge.jsonapi.core.model.JsonApiDocument document)
      Validates document against the bound context, then writes it through generator. The caller owns the generator and closes it.
    • writeValueAsString

      public String writeValueAsString(com.kazforge.jsonapi.mapping.MappedDocument mapped)
      Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then returns the JSON string.
    • writeValueAsBytes

      public byte[] writeValueAsBytes(com.kazforge.jsonapi.mapping.MappedDocument mapped)
      Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then returns the UTF-8 JSON bytes.
    • writeValue

      public void writeValue(OutputStream out, com.kazforge.jsonapi.mapping.MappedDocument mapped)
      Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it to out. The stream is not closed; it remains caller-owned, including its buffering and flushing lifecycle. Only the generator created for this call is closed.
    • writeValue

      public void writeValue(Writer out, com.kazforge.jsonapi.mapping.MappedDocument mapped)
      Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it to out. The writer is not closed; it remains caller-owned, including its buffering and flushing lifecycle. Only the generator created for this call is closed.
    • writeValue

      public void writeValue(tools.jackson.core.JsonGenerator generator, com.kazforge.jsonapi.mapping.MappedDocument mapped)
      Validates mapped.document() against the bound context composed with mapped's sparse-fieldset linkage exemptions, then writes it through generator. The caller owns the generator and closes it.