Trouble with XML Serialization in Spring Boot: Custom Objects Not Mapping Correctly
Quick question that's been bugging me - This might be a silly question, but I'm facing an issue with XML serialization in my Spring Boot application when trying to return a custom object as XML. I'm using JAXB for the serialization, but it seems like my nested objects are not being serialized correctly. The outer object serializes fine, but the nested objects are completely omitted from the output. Hereβs a simplified version of my classes: ```java import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Parent { private String name; private Child child; @XmlElement public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlElement public Child getChild() { return child; } public void setChild(Child child) { this.child = child; } } @XmlRootElement public class Child { private String value; @XmlElement public String getValue() { return value; } public void setValue(String value) { this.value = value; } } ``` In my controller, I return an instance of `Parent` like this: ```java @GetMapping("/parent") public Parent getParent() { Parent parent = new Parent(); parent.setName("Parent Name"); Child child = new Child(); child.setValue("Child Value"); parent.setChild(child); return parent; } ``` Despite everything appearing fine, the serialized XML output looks like this: ```xml <parent> <name>Parent Name</name> </parent> ``` I have tried making sure that the `Child` class is annotated with `@XmlRootElement`, but that didn't change anything. I've also checked my dependencies and Iβm using Spring Boot 2.5.4 and JAXB 2.3.1. Could there be any configuration that Iβm missing or is there a specific reason why nested objects would be omitted during serialization? Any help would be greatly appreciated! This is part of a larger API I'm building. My development environment is macOS. Any help would be greatly appreciated! Is this even possible?