Java 21 - String Templates - Directly Generate JSON Doc Object Instance

preview_player
Показать описание
Java 21 - String Templates - Directly Generate JSON Doc Object Instance

👉 Use case
Out of the box, we need a way for a String Template to
take a input template and return a
JSON Document Object instance directly

👉 Advantage
✅ Abstracts the code for String interpolation for JSON values and
✅ Decouples JSON Doc Object instance creation implementation

👉 Current Code Methodology
✅ Construct a String denoting a JSON document (keys)
✅ Then, Format it to substitute JSON key values
✅ Finally, JSON parser used to obtain an instance of JSON Object

Aim is to express JSON structure of the string directly in the code and
Java runtime should transform the string into a JSON Object

👉 Java 21 String Templates

✅ Now in Java 21 we can create a String Template Processor implementation
which takes a Template argument
returns a JSON Object instance

✅ Using - String Template -
Functional Interface Processor implementation

✅ We are using Eclipse Parsson implementation of
Jakarta EE 10 JSON-P specifications in this example which
can be abstracted in future

Sunit Ghosh
#java21 #OpenJDK21 #Java21StringTemplates
Рекомендации по теме
visit shbcf.ru