Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes use of JAXB API via jackson-dataformat-xml #29384

Merged
merged 2 commits into from
Dec 13, 2023

Conversation

linghengqian
Copy link
Member

@linghengqian linghengqian commented Dec 12, 2023

For #26041.

Changes proposed in this pull request:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.954 s <<< FAILURE! -- in org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtilsTest
[ERROR] org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtilsTest.assertParse -- Time elapsed: 0.869 s <<< ERROR!
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 optional type `java.util.Optional<java.lang.String>` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jdk8" to enable handling (through reference chain: org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobId["jobType"]->org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType["toBeStartDisabledNextJobType"])
        at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
        at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1330)
        at com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer.serialize(UnsupportedTypeSerializer.java:35)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:183)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:183)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:502)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341)
        at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4793)
        at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:4038)
        at org.apache.shardingsphere.infra.util.json.JsonUtils.toJsonString(JsonUtils.java:61)
        at org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobId.marshalSuffix(PipelineJobId.java:54)
        at org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobIdUtils.marshal(PipelineJobIdUtils.java:52)
        at org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtilsTest.assertParse0(PipelineJobIdUtilsTest.java:44)
        at org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtilsTest.assertParse(PipelineJobIdUtilsTest.java:38)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

@Getter
public final class JDBCRepositorySQL {

@XmlAttribute(required = true)
@JacksonXmlProperty(isAttribute = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost required here? Is there no such property with JacksonXmlProperty?

Copy link
Member Author

@linghengqian linghengqian Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is no direct equivalent.

Unfortunately XML is special: due to structure being what it is, empty Element looks either as "Object with no properties" or "empty String".

final XmlMapper xmlMapper = new XmlMapper();

xmlMapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I'm not sure how the JAXB API handles the required attribute.

  • In my local unit test, jaxb-runtime does not throw an exception for empty elements, but gets null values normally like jackson-dataformat-xml. required seems to be just for IDE censorship.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see. It could be better to open an issue since we need more investigation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrymanu terrymanu added this to the 5.4.2 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
3 participants