Skip to content

[Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine)#3691

Open
souvikghosh04 wants to merge 1 commit into
mainfrom
Usr/sogh/mssql-json-phase2
Open

[Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine)#3691
souvikghosh04 wants to merge 1 commit into
mainfrom
Usr/sogh/mssql-json-phase2

Conversation

@souvikghosh04

@souvikghosh04 souvikghosh04 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Adds support for the SQL Server 2025 JSON column type by treating it exactly like a normal text (string) column. Reading, writing, filtering, and sorting all reuse the paths DAB already has for strings — no new type, no special handling.

The change

Two small edits to the engine:

  1. Map the type — tell DAB that a JSON column is a string.
  2. Map the errors — when SQL Server rejects invalid JSON, return HTTP 400 (Bad Request) instead of a generic 500.

Both are covered by new unit tests.

This PR is intentionally scoped to just the engine change. The database test table and end-to-end (REST/GraphQL) tests are not included here because they need a real SQL Server 2025 database — and our CI currently runs on LocalDB, which doesn't understand the JSON type yet. Those tests come in the next phase.

Delivery plan

Phase What Status
1 Upgrade to .NET 10 + SqlClient 6.x (prerequisite) ✅ Merged (#3656)
2 JSON type + error mapping (this PR) 🚧 In review
3 Test table + full REST/GraphQL/MCP tests Next
4 Error/filter edge cases + regression After

Notes

@souvikghosh04 souvikghosh04 force-pushed the Usr/sogh/mssql-json-phase2 branch from 4edabac to 6bed2da Compare July 1, 2026 13:54
…s (Phase 2)

Treat SQL Server 2025+ JSON columns exactly like string columns (2026-06-09 design, issue #2768). Engine-only change validated by unit tests.

- TypeHelper._sqlDbTypeToType[SqlDbType.Json] = typeof(string) (T004)

- SqlTypeConstants: register json as supported literal (T004)

- MsSqlDbExceptionParser BadRequestExceptionCodes += 13608-13614 so SQL JSON errors map to HTTP 400 (T006)

- unit tests for json type mapping and 400 error mapping (T005/T007)

The profiles DB fixture (T002) and Profile config entity (T003) are DEFERRED to Phase 3: the native json type requires SQL Server 2025+/Azure SQL and cannot be created on the LocalDB engine used by CI. They ship with the Phase 3 integration tests behind server-version gating.

No changes to PostgreSQL/MySQL/DwSql/CosmosDB (FR-012).
@souvikghosh04 souvikghosh04 force-pushed the Usr/sogh/mssql-json-phase2 branch from 6bed2da to 9e5a38d Compare July 1, 2026 14:07
@souvikghosh04 souvikghosh04 changed the title [Phase 2] Enable MSSQL JSON data type - type mapping, error codes & fixtures [Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine) Jul 1, 2026
@souvikghosh04 souvikghosh04 marked this pull request as ready for review July 2, 2026 09:43
Copilot AI review requested due to automatic review settings July 2, 2026 09:43
@souvikghosh04 souvikghosh04 self-assigned this Jul 2, 2026
@souvikghosh04 souvikghosh04 added this to the July 2026 milestone Jul 2, 2026
@souvikghosh04 souvikghosh04 linked an issue Jul 2, 2026 that may be closed by this pull request
@souvikghosh04 souvikghosh04 moved this from Todo to Review In Progress in Data API builder Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds SQL Server 2025 JSON column support by treating JSON exactly like a string in DAB’s type system, and improves error handling so SQL JSON validation failures map to a client error instead of a generic server error.

Changes:

  • Map SqlDbType.Json (and the "json" type literal) to CLR string so existing string read/write/filter/sort paths apply.
  • Map SQL Server JSON validation error codes (13608–13614) to HTTP 400 (Bad Request) in the MSSQL exception parser.
  • Add/extend tests validating the new type mapping and HTTP status mapping.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Core/Services/TypeHelper.cs Adds SqlDbType.Json -> string mapping so JSON behaves like a string in CLR/type resolution.
src/Core/Models/SqlTypeConstants.cs Marks "json" as a supported SQL type literal for metadata/type-resolution test coverage.
src/Core/Resolvers/MsSqlDbExceptionParser.cs Adds JSON validation error codes to the “bad request” classification.
src/Service.Tests/OpenApiDocumentor/CLRtoJsonValueTypeUnitTests.cs Adds a targeted test asserting "json" resolves to string and maps to JsonDataType.String.
src/Service.Tests/UnitTests/DbExceptionParserUnitTests.cs Adds a data-driven test asserting JSON validation errors map to HTTP 400.

Comment on lines +33 to +36
"4457", "4933", "4934", "4936", "4988", "8102",
// JSON data type validation errors (SQL Server 2025+). Invalid JSON
// supplied for a json column is a client error, mapped to HTTP 400.
"13608", "13609", "13610", "13611", "13612", "13613", "13614"
Comment on lines +130 to +133
Assert.AreEqual(
System.Net.HttpStatusCode.BadRequest,
dbExceptionParser.GetHttpStatusCodeForException(SqlTestHelper.CreateSqlException(number)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

Phase 2: Map type and error code for JSON datatype

4 participants