Skip to content

Struson 0.8.0

Latest

Choose a tag to compare

@Marcono1234 Marcono1234 released this 12 Nov 16:25

Changes

  • Minimum Rust version (MSRV) is now 1.91.0

  • JsonStreamReader does not perform any buffering anymore
    Depending on the use case a std::io::BufReader should be used, for example when reading from a file or a network connection.

  • (Breaking) Removed JsonStreamReader::reader_mut
    (The internal implementation uses std::io::Bytes now, and that does not support obtaining a reference to the underlying Read)

  • (Breaking) Refactored reader and writer error types

    • ReaderError
      • location is now common to all ReaderError variants
      • fields are now private; public methods are provided to get access to its data
      • reduced stack size of ReaderError
    • removed the separate JsonSyntaxError struct
    • converted some tuple structs to structs with fields to make it clearer what the contained data represents
  • (Breaking) Improved settings for multiple top-level values for JSON reader and writer

  • (Breaking) Clarified that generally reader errors are not safe to retry, regardless of kind
    Previously the documentation said UnexpectedValueType and UnexpectedStructure were safe to retry in most cases, but the list of exclusions was incomplete. And in general these two errors can be avoided by using peek() respectively has_next().

  • (New) Added JsonReader::next_number_int
    New experimental method for reading integer numbers more efficiently than JsonReader::next_number. Please provide feedback in #167.

  • (New) Added JsonReader::deserialize_next_recoverable
    New experimental method which supports recovering from some errors. Please provide feedback in #180.

  • (New) Added support for reading and writing empty JSON documents
    Disabled by default; can be enabled with allow_empty_document field of reader and writer settings.
    Useful when producing or consuming potentially empty JSON Lines documents.

  • (New) Added convenience method is_io() to reader-related errors
    Can be useful for determining whether an error is caused by an IO error from the underlying reader, or due to invalid or malformed JSON data.

  • (New) Added a dedicated reader error kind for invalid UTF-8 data
    Previously it was reported as IO error.

  • (New) Added JsonReader::previous_json_path and new display_json_path
    Can be used for better error reporting when enforcing additional constraints for a JSON value after it has been read, for example that a JSON string value must match a certain pattern.

  • (New) Added NumberFormatter trait
    New experimental trait which supports customizing how JSON numbers are formatted for a JSON writer. Please provide feedback in #184.

  • (New) Added opt-in detection of duplicate member names when reading (thanks @HardMax71!)
    Disabled by default; can be enabled with the new ReaderSettings::duplicate_name_detection.

Simple API

  • (New) Added ValueReader::read_deserialize_recoverable
    New experimental method which supports recovering from some errors. Please provide feedback in #180.

  • (Breaking) ValueReader::read_string_with_reader must now fully consume the JSON string
    No implicit skipping of the remainder of the value is performed anymore. The new method StringValueReader::skip_remainder can be used to explicitly skip the remainder (if any).

Custom JsonReader & JsonWriter

These changes are most likely only relevant when implementing a custom JsonReader or JsonWriter.

  • Added default implementations for
    • JsonReader::deserialize_next, JsonReader::transfer_to
    • JsonWriter::serialize_value

Minor changes

These changes are probably not noticeable to most users.

  • [Simple API] For read_string_with_reader don't redundantly wrap the underlying error from JsonStreamReader

  • [Simple API] Improved error message for string value reader

  • [Simple API] Fixed when errors were repeated after a previous error, some of them did not indicate that they represent a previous error

  • Added Debug as supertrait for FiniteNumber and FloatingPointNumber

  • Fixed wrong panic messages when using JsonStreamWriter incorrectly

  • Improved string writing performance for JsonStreamWriter with default settings

  • Changed display format of JSON paths in errors to use the format of the JSONPath standard
    However, this is an implementation detail and the format may change in the future, see the display_json_path function for details.

  • Removed From<std::io::Error> for TransferError::WriterError
    This was error-prone because the IO error could have also originated from the JSON reader, not the writer. So the choice which TransferError variant to construct should be explicit.

  • Updated Serde integration behavior to match serde_json 1.0.150
    In particular, enum deserialization has been changed, see also serde-rs/json#1324. Most likely has no effect for most use cases.

  • [Build] Removed strum dependency (thanks @mcbegamerxx954!)

  • [Build] Removed duplicate dependency