Skip to content

Conversation

k-paxian
Copy link
Owner

No description provided.

This commit introduces a `rawJson` boolean property to `JsonProperty`.

When `rawJson` is true on a String field:
- Serialization: A string field containing valid JSON is embedded as raw JSON
  (not a JSON string). If the string is not valid JSON, it's serialized
  as a regular string. Empty strings or the literal string "null"
  are serialized as JSON null.
- Deserialization: A JSON object/array in the input is converted to its
  string representation and stored in the String field. If the input
  is a JSON primitive (string, number, boolean), it's converted to its
  string representation. If the input is JSON null, the field is set to null.

Includes:
- Modifications to `JsonProperty` in `mapper/lib/src/model/annotations.dart`.
- Updated serialization logic in `_serializeObject` in `mapper/lib/src/mapper.dart`.
- Updated deserialization logic in `_deserializeObject` in `mapper/lib/src/mapper.dart`.
- New unit tests in `perf-test/test/unit/test.raw_json.dart` covering
  various serialization and deserialization scenarios for `rawJson`.
- Adjustments to test setup in `test.raw_json.dart` based on your feedback
  (removal of redundant `setUpAll`).

Note: I encountered issues with test execution in the development environment,
which I suspect are related to build caching or path dependency resolution
within Docker. I believe the implemented code changes are correct
based on the requirements and logic verification.
This commit introduces a `rawJson` boolean property to `JsonProperty`.
When `rawJson` is true on a String field, the behavior is as follows:

Serialization:
- If the String field contains a valid JSON string (object or array),
  it is embedded directly as a raw JSON structure in the output.
- If the String field contains an invalid JSON string, an empty string,
  or the literal string "null", it is serialized as a null value or
  a plain JSON string respectively.

Deserialization:
- If the incoming JSON value for the field is a JSON object or array,
  it is converted to its string representation and stored in the String field.
- If the incoming JSON value is null, the field is set to null.
- If the incoming JSON value is a JSON primitive (string, number, boolean),
  it is converted to its string representation and stored in the String field.

Changes include:
- Added `rawJson` to `JsonProperty` in `model/annotations.dart`.
- Modified serialization logic in `_serializeObject` in `mapper.dart`
  to handle raw JSON string serialization by embedding parsed Maps/Lists.
- Modified deserialization logic in `DefaultConverter.fromJSON` in
  `model/converters.dart` to convert incoming JSON objects/arrays/primitives
  to their string representation for `rawJson: true` String fields.
- Added comprehensive unit tests in `perf-test/test/unit/test.raw_json.dart`.
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