Skip to content

Commit ef51583

Browse files
dfcoffinclaude
andcommitted
fix: update MigrationVerificationTest to use Jackson 3 instead of pure JAXB
The production code uses Jackson 3 XmlMapper with JAXB annotations (hybrid approach), not pure JAXB. Updated the test to match production implementation. This fixes the CI/CD failure where pure JAXB couldn't handle @XmlTransient annotations on utility methods in POJOs with @XmlAccessorType(PROPERTY). Jackson 3 handles this correctly, which is why all other tests pass. Related: #62 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7aea5c9 commit ef51583

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

openespi-common/src/test/java/org/greenbuttonalliance/espi/common/MigrationVerificationTest.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.greenbuttonalliance.espi.common;
2121

22+
import com.fasterxml.jackson.annotation.JsonInclude;
2223
import org.greenbuttonalliance.espi.common.domain.common.IdentifiedObject;
2324
import org.greenbuttonalliance.espi.common.domain.usage.UsagePointEntity;
2425
import org.greenbuttonalliance.espi.common.domain.customer.entity.CustomerEntity;
@@ -28,15 +29,21 @@
2829
import org.greenbuttonalliance.espi.common.dto.SummaryMeasurementDto;
2930
import org.junit.jupiter.api.Test;
3031
import org.junit.jupiter.api.DisplayName;
32+
import tools.jackson.databind.AnnotationIntrospector;
33+
import tools.jackson.databind.SerializationFeature;
34+
import tools.jackson.databind.cfg.DateTimeFeature;
35+
import tools.jackson.databind.introspect.JacksonAnnotationIntrospector;
36+
import tools.jackson.databind.util.StdDateFormat;
37+
import tools.jackson.dataformat.xml.XmlAnnotationIntrospector;
38+
import tools.jackson.dataformat.xml.XmlMapper;
39+
import tools.jackson.dataformat.xml.XmlWriteFeature;
40+
import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector;
41+
import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule;
3142

3243
import jakarta.validation.Validation;
3344
import jakarta.validation.Validator;
3445
import jakarta.validation.ValidatorFactory;
35-
import jakarta.xml.bind.JAXBContext;
36-
import jakarta.xml.bind.JAXBException;
37-
import jakarta.xml.bind.Marshaller;
3846

39-
import java.io.StringWriter;
4047
import java.util.UUID;
4148

4249
import static org.junit.jupiter.api.Assertions.*;
@@ -63,18 +70,31 @@ void jakartaValidationShouldWork() {
6370
}
6471

6572
@Test
66-
@DisplayName("Jakarta XML Binding should work for DTOs")
67-
void jakartaXmlBindingShouldWork() throws JAXBException {
68-
JAXBContext context = JAXBContext.newInstance(UsagePointDto.class);
69-
Marshaller marshaller = context.createMarshaller();
70-
73+
@DisplayName("Jackson 3 XML with JAXB annotations should work for DTOs")
74+
void jackson3XmlWithJaxbAnnotationsShouldWork() throws Exception {
75+
// Production code uses Jackson 3 XmlMapper with JAXB annotation support
76+
AnnotationIntrospector intr = XmlAnnotationIntrospector.Pair.instance(
77+
new JakartaXmlBindAnnotationIntrospector(),
78+
new JacksonAnnotationIntrospector()
79+
);
80+
81+
XmlMapper xmlMapper = XmlMapper.xmlBuilder()
82+
.annotationIntrospector(intr)
83+
.addModule(new JakartaXmlBindAnnotationModule()
84+
.setNonNillableInclusion(JsonInclude.Include.NON_EMPTY))
85+
.enable(SerializationFeature.INDENT_OUTPUT)
86+
.enable(DateTimeFeature.WRITE_DATES_WITH_ZONE_ID)
87+
.disable(XmlWriteFeature.WRITE_NULLS_AS_XSI_NIL)
88+
.defaultDateFormat(new StdDateFormat())
89+
.build();
90+
7191
// Create a simple DTO without constructor arguments
7292
UsagePointDto dto = new UsagePointDto();
73-
74-
StringWriter writer = new StringWriter();
75-
assertDoesNotThrow(() -> marshaller.marshal(dto, writer));
76-
77-
String xml = writer.toString();
93+
94+
// Marshal using Jackson 3
95+
String xml = assertDoesNotThrow(() -> xmlMapper.writeValueAsString(dto));
96+
97+
// Verify XML structure
7898
assertTrue(xml.contains("UsagePoint"));
7999
assertTrue(xml.contains("http://naesb.org/espi"));
80100
}

0 commit comments

Comments
 (0)