Skip to content

Bind a peek against a stated type, and check a body's own schema - #27

Merged
oobles merged 1 commit into
mainfrom
feat/peek-readas
Sep 28, 2026
Merged

oobles merged 1 commit into
mainfrom
feat/peek-readas

Conversation

@oobles

@oobles oobles commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

tson-java implemented UPSTREAM.md #1: TsonObjectReader.readAs(TsonDocumentPeek, String, Class) (litterat/ltr8-io-tson-java#592). This PR adopts it, and closes #3, which the same change answered.

Adopting #1

  • New TsonHttpCodec.readObjectAs(TsonDocumentPeek, …): binds against a stated type after the header has been read, with the body read once.
  • Routing fix: TsonSchemaVersions.Routed.readObjectAs reads a TSON body through it. So a TSON body naming its version only in the TSON-Schema header is now read against that version's schema. It used to be read with no schema at all, because bind mode couldn't continue the peek.

Closing #3 by decision, and the behaviour change

Upstream keeps readAs's override of a document's own !!schema deliberately. Its Javadoc leaves the comparison to the caller, and that comparison was only blocked by #1. So the codec makes it now:

  • The check: readObjectAs / readTreeAs read the start of a TSON body and compare its !!schema with the stated one by canonical identity, so scheme and pin don't count.
  • Behaviour change: a disagreement is now a 400 conflicting-schema (the same type TsonSchemaHeader uses). Before, it was silently read against the stated schema.
  • A body naming no schema is still read against the stated one.

Tests

  • TsonHttpCodecTest:
    • a disagreeing !!schema is a 400 in bind and tree mode;
    • agreement across scheme and pin, and a body naming no schema, both read;
    • the check reads the body once, over a stream that can't be rewound.
  • TsonSchemaVersionsTest: a header-only TSON body is judged by its version's schema.
  • UpstreamGapsTest:
    • the new reader entry point is pinned;
    • the override test is re-documented as upstream's decision. It's kept so that, if upstream ever starts refusing on its own, the codec's duplicate check gets noticed.

Docs

./gradlew build javadoc and ./gradlew build -Ptson.published=true (after a fresh publishToMavenLocal) pass.

🤖 Generated with Claude Code

tson-java's object reader now continues a peek against a stated type --
readAs(TsonDocumentPeek, String, Class) -- which closes UPSTREAM.md #1.
TsonHttpCodec gains readObjectAs(peek, ...), and TsonSchemaVersions.Routed
reads a TSON body through it, so one naming its version only in the
TSON-Schema header is read against that version's schema rather than
schemaless.

The same change answers #3 by decision: readAs lets a stated schema override
the document's own !!schema and leaves the comparison to the caller. So the
codec makes it. readObjectAs and readTreeAs peek a TSON body and answer a
!!schema disagreeing with the stated one by canonical identity 400
conflicting-schema, where it was read against the stated schema in silence.
Both items come out of UPSTREAM.md; the override stays pinned in
UpstreamGapsTest so the codec's copy of the rule is noticed if upstream starts
refusing, and the new reader entry point is pinned beside it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@oobles
oobles merged commit f3fea06 into main Sep 28, 2026
1 check passed
@oobles
oobles deleted the feat/peek-readas branch September 28, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant