Class Json
ObjectMapper.
The mapper is constructed once in a static initializer and is never mutated afterwards. Only
the thread-safe ObjectReader and ObjectWriter views are exposed (directly or via
convenience helpers), which keeps all usage safe under the parallel experiment runs that
dokimos-core performs.
Configuration of note:
StreamReadFeature.STRICT_DUPLICATE_DETECTIONis enabled on the comparison reader so duplicate object keys (a real signal in an evaluation) fail loudly rather than being silently collapsed.DeserializationFeature.FAIL_ON_TRAILING_TOKENSis enabled so trailing garbage after a value is rejected.- Non-finite floating point values (NaN, Infinity) are rejected when parsing (the
JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERSread feature is disabled). Jackson has no equivalent throw-on-write for non-finite doubles, so the structural comparator additionally rejects in-memory non-finite values before comparison; this keeps Jackson's surprisingNaN == NaNout of eval results.
This class is internal API. It is not part of the public, supported surface of dokimos-core and may change without notice.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.ObjectWriterA thread-safe writer producing compact (single-line) JSON.static com.fasterxml.jackson.databind.ObjectReaderA thread-safe reader configured for structural comparison: strict duplicate-key detection is enabled so{"x":1,"x":2}fails rather than silently collapsing.static <T> TConverts a value into an instance described by a JacksonJavaType, supporting generic targets such asList<Foo>.static <T> TConverts a value into an instance oftypewithout an intermediate textual round-trip.static com.fasterxml.jackson.databind.ObjectWriterA thread-safe writer producing pretty-printed JSON.static <T> TParses a JSON string into the generic target captured by a JacksonTypeReference, using the strict comparison reader so duplicate object keys are rejected alongside the NaN/Infinity and trailing-token tightening that applies to every reader.static <T> TParses a JSON string into an instance described by a JacksonJavaType, supporting generic targets such asList<Foo>.static <T> TParses a JSON string into an instance oftype.static com.fasterxml.jackson.databind.ObjectReaderreader()A thread-safe reader over the shared, immutable mapper.static com.fasterxml.jackson.databind.JavaTyperesolveType(Type type) Resolves a JacksonJavaTypefrom a genericType.static com.fasterxml.jackson.databind.JsonNodeConverts an arbitrary value to aJsonNodetree (the in-memory model the structural comparator works against).static StringwriteCompact(Object value) Serializes a value to compact (single-line) JSON.static StringwritePretty(Object value) Serializes a value to pretty-printed JSON.
-
Method Details
-
reader
public static com.fasterxml.jackson.databind.ObjectReader reader()A thread-safe reader over the shared, immutable mapper. Use for general value conversion.- Returns:
- the shared
ObjectReader
-
comparisonReader
public static com.fasterxml.jackson.databind.ObjectReader comparisonReader()A thread-safe reader configured for structural comparison: strict duplicate-key detection is enabled so{"x":1,"x":2}fails rather than silently collapsing.- Returns:
- the shared comparison
ObjectReader
-
compactWriter
public static com.fasterxml.jackson.databind.ObjectWriter compactWriter()A thread-safe writer producing compact (single-line) JSON.- Returns:
- the shared compact
ObjectWriter
-
prettyWriter
public static com.fasterxml.jackson.databind.ObjectWriter prettyWriter()A thread-safe writer producing pretty-printed JSON.- Returns:
- the shared pretty-printing
ObjectWriter
-
convert
Converts a value into an instance oftypewithout an intermediate textual round-trip.- Type Parameters:
T- the target type- Parameters:
value- the source value (may benull)type- the target class- Returns:
- the converted value, or
nullifvalueisnull - Throws:
IllegalArgumentException- if the value cannot be converted totype
-
convert
Converts a value into an instance described by a JacksonJavaType, supporting generic targets such asList<Foo>.- Type Parameters:
T- the target type- Parameters:
value- the source value (may benull)type- the target Jackson type- Returns:
- the converted value, or
nullifvalueisnull - Throws:
IllegalArgumentException- if the value cannot be converted totype
-
toNode
Converts an arbitrary value to aJsonNodetree (the in-memory model the structural comparator works against).- Parameters:
value- the source value (may benull)- Returns:
- the value as a
JsonNode; anullvalue yields a Jackson null node
-
writeCompact
Serializes a value to compact (single-line) JSON.- Parameters:
value- the value to serialize- Returns:
- the compact JSON string
- Throws:
IllegalArgumentException- if the value cannot be serialized
-
writePretty
Serializes a value to pretty-printed JSON.- Parameters:
value- the value to serialize- Returns:
- the pretty-printed JSON string
- Throws:
IllegalArgumentException- if the value cannot be serialized
-
read
Parses a JSON string into an instance oftype.Backed by
reader().forType(type), which returns a fresh, type-bound view of the shared immutable mapper without mutating it — so this is safe under the parallel experiment runs dokimos-core performs.- Type Parameters:
T- the target type- Parameters:
json- the JSON text to parsetype- the target class- Returns:
- the parsed value (the JSON literal
nullparses tonull) - Throws:
IllegalArgumentException- if the text is not valid JSON or does not matchtype
-
read
Parses a JSON string into an instance described by a JacksonJavaType, supporting generic targets such asList<Foo>.Backed by
reader().forType(type), which returns a fresh, type-bound view of the shared immutable mapper without mutating it — so this is safe under the parallel experiment runs dokimos-core performs.- Type Parameters:
T- the target type- Parameters:
json- the JSON text to parsetype- the target Jackson type- Returns:
- the parsed value (the JSON literal
nullparses tonull) - Throws:
IllegalArgumentException- if the text is not valid JSON or does not matchtype
-
read
Parses a JSON string into the generic target captured by a JacksonTypeReference, using the strict comparison reader so duplicate object keys are rejected alongside the NaN/Infinity and trailing-token tightening that applies to every reader.This is the load-path entry point for dataset and server JSON: malformed structured input (a duplicate key, a
NaNtoken, trailing garbage) fails here at parse time rather than surfacing confusingly later during evaluation.- Type Parameters:
T- the target type- Parameters:
json- the JSON text to parsetype- the captured generic target type- Returns:
- the parsed value (the JSON literal
nullparses tonull) - Throws:
IllegalArgumentException- if the text is not valid JSON or does not matchtype
-
resolveType
Resolves a JacksonJavaTypefrom a genericType. Used to bridge anOutputType<T>'s captured type into the conversion machinery.- Parameters:
type- the generic type to resolve- Returns:
- the corresponding Jackson
JavaType
-