From e0e4f32d68d4434032c75f864085ad37ef8702f5 Mon Sep 17 00:00:00 2001 From: linghengqian Date: Thu, 28 Dec 2023 11:33:27 +0800 Subject: [PATCH] Check specific properties when deserializing XML file --- .../sqlfederation/optimizer/it/TestCases.java | 2 ++ .../sqlfederation/optimizer/it/TestCasesLoader.java | 2 +- .../standalone/jdbc/sql/JDBCRepositorySQL.java | 13 +++++++++++++ .../jdbc/sql/JDBCRepositorySQLLoader.java | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCases.java b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCases.java index aaddf5b660ced..b84e92c7806fb 100644 --- a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCases.java +++ b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCases.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.sqlfederation.optimizer.it; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import lombok.Getter; @@ -32,5 +33,6 @@ public final class TestCases { @JacksonXmlProperty(localName = "test-case") + @JacksonXmlElementWrapper(useWrapping = false) private final Collection testCases = new LinkedList<>(); } diff --git a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCasesLoader.java b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCasesLoader.java index 54ea2a2a37494..c8413dfc7c4c5 100644 --- a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCasesLoader.java +++ b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/TestCasesLoader.java @@ -34,7 +34,7 @@ public final class TestCasesLoader { private static final TestCasesLoader INSTANCE = new TestCasesLoader(); - private static final ObjectMapper XML_MAPPER = XmlMapper.builder().defaultUseWrapper(false).build(); + private static final ObjectMapper XML_MAPPER = XmlMapper.builder().build(); /** * Get singleton instance. diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQL.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQL.java index 06a934555d414..ff13c72344b6f 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQL.java +++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQL.java @@ -17,41 +17,54 @@ package org.apache.shardingsphere.mode.repository.standalone.jdbc.sql; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import lombok.Getter; /** * JDBC repository SQL. + * `required` in {@link com.fasterxml.jackson.annotation.JsonProperty} only provides Metadata without detecting Null values, which is actually consistent with the design of the JAXB API. + * See FasterXML/jackson-dataformat-xml#625 + * + * @see JsonProperty */ @JacksonXmlRootElement(localName = "sql") @Getter public final class JDBCRepositorySQL { + @JsonProperty(required = true) @JacksonXmlProperty(isAttribute = true) private String type; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "driver-class-name", isAttribute = true) private String driverClassName; @JacksonXmlProperty(localName = "default", isAttribute = true) private boolean isDefault; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "create-table") private String createTableSQL; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "select-by-key") private String selectByKeySQL; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "select-by-parent") private String selectByParentKeySQL; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "insert") private String insertSQL; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "update") private String updateSQL; + @JsonProperty(required = true) @JacksonXmlProperty(localName = "delete") private String deleteSQL; } diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java index fa5f68bdbb504..870aba4b7b114 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java +++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java @@ -58,7 +58,7 @@ public final class JDBCRepositorySQLLoader { private static final Collection JAR_URL_PROTOCOLS = new HashSet<>(Arrays.asList("jar", "war", "zip", "wsjar", "vfszip")); - private static final ObjectMapper XML_MAPPER = XmlMapper.builder().defaultUseWrapper(false).build(); + private static final ObjectMapper XML_MAPPER = XmlMapper.builder().build(); /** * Load JDBC repository SQL.