javatype

package
v0.0.0-...-c671013 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package javatype classifies a Java type for two decisions we make repeatedly: do we need an @type tag when generic-invoking (contract side), and what JSON placeholder do we render when describing a method (schema side). Today both decisions live in ~12 scattered string whitelists; this package centralises them.

The package has no external Go dependencies; callers pass a tiny ClassLookup so we stay free of facadesemantic and can be unit-tested with hand-built fakes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderPlaceholder

func RenderPlaceholder(kind PlaceholderKind) json.RawMessage

RenderPlaceholder returns the JSON literal for kind. Kept as a separate function from Placeholder so callers can override the literal without re-implementing classification.

Types

type ClassLookup

type ClassLookup interface {
	Superclass(fqn string) (string, bool)
	Interfaces(fqn string) ([]string, bool)
}

ClassLookup exposes the superclass / interface chain of a user-space Java type. Implementations must return empty strings / empty slices for types they do not know about; they MUST NOT panic.

type PlaceholderKind

type PlaceholderKind int

PlaceholderKind labels the JSON skeleton we render for a type. Each kind maps to exactly one placeholder literal. The set is intentionally small (six entries) — any type we cannot classify falls back to PlaceholderObject, which renders `null` and leaves the agent to describe it further.

const (
	PlaceholderObject PlaceholderKind = iota
	PlaceholderString
	PlaceholderBool
	PlaceholderNumber
	PlaceholderDecimal
	PlaceholderDate
	PlaceholderCollection
	PlaceholderMap
)

func Placeholder

func Placeholder(fqn string) PlaceholderKind

Placeholder returns the kind of JSON skeleton for fqn. It is independent of Classify: a type may be Passthrough for invocation but still need a specific literal for describe-time rendering (e.g. LocalDate → "1970-…").

type Role

type Role int

Role names the invocation-time treatment of a type.

  • UserType the agent must attach an @type tag when the value is nested inside a generic container (Object field, List<?>, Map<?,?>). Plain DTOs, custom exceptions, @JsonSubTypes bases, etc.
  • Container the type is a Collection or Map. Child values still need @type decisions; the container itself is transparent to Hessian2.
  • Passthrough the type is a primitive, wrapper, String, Number, Date, Temporal, CharSequence, or enum. Never needs @type.
const (
	RoleUnknown Role = iota
	RolePassthrough
	RoleContainer
	RoleUserType
)

func Classify

func Classify(fqn string, lookup ClassLookup) Role

Classify returns the Role of fqn by walking the supertype chain. Unknown types (not in the registry, not in any built-in set) are treated as UserType — the safer default for @type injection, since a missing tag causes Hessian2 deserialisation failures at the server, while a redundant tag is usually tolerated.

The walk terminates when any ancestor matches one of the built-in sets:

passthrough:  primitives, wrappers, Number, CharSequence, Date, Temporal,
              Enum, UUID, BigInteger, BigDecimal
container:    Collection, Map (and their subtypes)

Arrays (trailing "[]") and parameterised names ("List<String>") are normalised by stripping the suffix before lookup.

func (Role) String

func (r Role) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL