Support JSON binding with the JDK's built-in JSON API (`jdk.incubator.json`)

Đang mở
#37,610 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, json
Lĩnh vực
api, backend-api-design

Hướng nghiên cứu

Read the linked proposal and inspect the prototype’s JsonRecordHttpMessageConverter to understand the proposed mapping and constraints. Compare the reflection, generated, hybrid, and tree-only options for spring-web and spring-messaging; done means the project has a decided scope and approach, or has explained why this belongs in a separate library.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status: waiting-for-triage
Use case

I want to build Spring MVC REST endpoints that read and write Java records as JSON without a third-party JSON library:

@PostMapping("/hello")
public HelloResponse hello(@RequestBody HelloRequest request) { ... }

The same records should also work as Kafka message payloads:

@KafkaListener(topics = "hello")
public void onHello(HelloRequest request) { ... }

JDK 28 ships an incubating JSON API (jdk.incubator.json) that parses JSON into a JsonValue tree and writes it back, but it does not map JSON to Java types.
Spring has HTTP and messaging converters for Jackson, Gson, JSON-B and Kotlin Serialization, but none for the JDK API.

Reasons for a JDK-only option:

  • Fewer dependencies for applications that only need simple JSON.
  • A smaller attack surface: jackson-databind has 86 advisories in OSV, 17 of them published in 2026.
  • GraalVM native images without reflection metadata for the JSON library.
What I have tried so far

A prototype on Spring Boot 4.1 / JDK 28-ea: https://github.com/drnow4u/springboot-jdk28-json

  • JsonRecordHttpMessageConverter, an AbstractHttpMessageConverter<Record> that maps JSON objects to and from records using reflection over record components (String, numeric and boolean types, nested records).
  • Malformed JSON or a wrong value type is mapped to HttpMessageNotReadableException (400).
  • The JDK parser has no size limits and repeats the offending input in its error messages, so the converter limits the body size (413) and shortens error messages.
  • Spring AOT already registers reflection hints for the records used in the controller signature, so option A below may work in a native image; this cannot be verified until GraalVM supports JDK 28.
Questions

The main design question is how the mapping should work:

  • A. Reflection over record components (what the prototype does). No setup, but needs AOT hints for native images.
  • B. Compile-time generated bindings (annotation processor), similar to Kotlin Serialization. No reflection, errors at compile time, but needs a processor on the build path.
  • C. Hybrid: generated bindings when present, reflection otherwise.
  • D. Tree types only: a converter for JsonValue / JsonObject / JsonArray, with mapping left to applications or libraries.

Whichever option is chosen, the mapping would be shared by an HttpMessageConverter (spring-web) and a MessageConverter (spring-messaging, used by @KafkaListener); a Kafka Serializer/Deserializer would belong in Spring for Apache Kafka.

Would the Spring team consider any of these for Spring Framework, and which one? Or should this live in a separate library until the JDK API leaves incubation?

The full proposal, covering security, performance, native image and open questions, is here:
https://github.com/drnow4u/springboot-jdk28-json/blob/main/docs/proposal-jdk-json-binding.md

Ngôn ngữ chính
Java
Star
60.3k
Fork
38.7k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
33

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-projects/spring-framework

Tất cả issue của spring-projects/spring-framework

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.