Skip to content

Commit

Permalink
Check specific properties when deserializing XML file (#29577)
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian authored Dec 31, 2023
1 parent 0bb53ad commit 3fbe164
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,5 +33,6 @@
public final class TestCases {

@JacksonXmlProperty(localName = "test-case")
@JacksonXmlElementWrapper(useWrapping = false)
private final Collection<TestCase> testCases = new LinkedList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://github.com/FasterXML/jackson-dataformat-xml/issues/625">FasterXML/jackson-dataformat-xml#625</a>
*
* @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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class JDBCRepositorySQLLoader {

private static final Collection<String> 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.
Expand Down

0 comments on commit 3fbe164

Please sign in to comment.