如何在Maven 中從JSON 產生Java 類別
從JSON 產生Java 來源檔案是物件到JSON 對應的一項有價值的技術和資料序列化。在這種情況下,我們尋求創建類似於以下內容的Java 類別:
class Address { private JSONObject mInternalJSONObject; Address(JSONObject json) { mInternalJSONObject = json; } String getStreetAddress() { return mInternalJSONObject.getString("streetAddress"); } String getCity() { return mInternalJSONObject.getString("city"); } } class Person { private JSONObject mInternalJSONObject; Person(JSONObject json) { mInternalJSONObject = json; } String getFirstName() { return mInternalJSONObject.getString("firstName"); } String getLastName() { return mInternalJSONObject.getString("lastName"); } Address getAddress() { return new Address(mInternalJSONObject.getJSONObject("address")); } }
要在Maven 專案中實現這一生成,您可以利用http://www.jsonschema2pojo.org 等綜合工具。或者,您可以使用 Maven 的 jsonschema2pojo 外掛程式:
<plugin> <groupid>org.jsonschema2pojo</groupid> <artifactid>jsonschema2pojo-maven-plugin</artifactid> <version>1.0.2</version> <configuration> <sourcedirectory>${basedir}/src/main/resources/schemas</sourcedirectory> <targetpackage>com.myproject.jsonschemas</targetpackage> <sourcetype>json</sourcetype> </configuration> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin>
對於 JSON 來源,您可以指定
近年來,JSON 模式規格取得了顯著進步,為定義結構規則提供了強大的機制。此外,jsonschema2pojo 專案提供了一個專用工具,可將 JSON 模式文件轉換為 Java DTO 類別。雖然仍在開發中,但它涵蓋了 JSON 模式的重要部分。使用者回饋對於其持續發展至關重要,您可以透過命令列或 Maven 插件提供。
以上是如何使用 jsonschema2pojo Maven 外掛程式從 JSON 產生 Java 類別?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Atom編輯器mac版下載
最受歡迎的的開源編輯器