diff --git a/pom.xml b/pom.xml index b84e2240e..2cc4451cb 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.lunasaw luna-common luna-common - 2.5.2 + 2.5.3 common is project which contains common utils https://github.com/lunasaw/luna-common @@ -20,18 +20,17 @@ UTF-8 4.4 - 3.12.0 - 1.15 - 2.11.0 + 3.14.0 + 1.16.0 + 2.15.1 5.2.1 - 31.1-jre - 2.10.6 + 32.1.3-jre 2.0.26 - 6.1.3 + 6.4.9 4.13.2 - 1.18.26 - 2.0.1.Final - 1.7.36 + 1.18.30 + 3.0.2 + 2.0.9 @@ -108,8 +107,8 @@ ${fast-json.version} - javax.validation - validation-api + jakarta.validation + jakarta.validation-api ${validation-api.version} @@ -273,4 +272,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/luna/common/check/ValidDataUtil.java b/src/main/java/com/luna/common/check/ValidDataUtil.java index 8e7661484..2a61caa30 100644 --- a/src/main/java/com/luna/common/check/ValidDataUtil.java +++ b/src/main/java/com/luna/common/check/ValidDataUtil.java @@ -3,13 +3,11 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; - -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; - import com.luna.common.exception.BaseException; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; /** * @author luna diff --git a/src/main/java/com/luna/common/xml/XmlBean.java b/src/main/java/com/luna/common/xml/XmlBean.java new file mode 100644 index 000000000..852978fc4 --- /dev/null +++ b/src/main/java/com/luna/common/xml/XmlBean.java @@ -0,0 +1,49 @@ +package com.luna.common.xml; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +import lombok.Getter; +import lombok.Setter; +import lombok.SneakyThrows; + +/** + * @author luna + * @date 2023/10/12 + */ +@Getter +@Setter +@XmlAccessorType(XmlAccessType.NONE) +public class XmlBean { + + /** + * 字符集, 支持 UTF-8 与 GB2312 + */ + private String charset = "UTF-8"; + + @SneakyThrows + @Override + public String toString() { + JAXBContext jaxbContext = JAXBContext.newInstance(this.getClass()); + Marshaller marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.setProperty(Marshaller.JAXB_ENCODING, charset); + + StringWriter writer = new StringWriter(); + marshaller.marshal(this, writer); + return writer.toString(); + } + + @SneakyThrows + public static Object parseObj(String xmlStr, Class clazz) { + JAXBContext jaxbContext = JAXBContext.newInstance(clazz); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + return unmarshaller.unmarshal(new StringReader(xmlStr)); + } +}