Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug - Marshalling an object that overrides the parent's method, t…
…he XML that created contains both child's and parent's tag, the problem was in serializeBody method in the reflection section. the condition should check if the super class contains the declared field that the child overrides. (#1590) * fix bug - Marshalling an object that overrides the parent's method, the XML that created contains both child's and parent's tag, the problem was in serializeBody method in the reflection section. the condition should check if the super class contains the declared field that the child overrides. DTOs: @XmlRootElement(name = "parent") public class ParentDTO { Protected String name; @xmlelement(name= “parentName”) getName) { return name; } setName(String name) { this.name = name; } } @XmlRootElement(name = "child") public class ChildDTO extends ParentDTO { @OverRide @xmlelement(name="childName") public String getName() { return name; } } Program: Child child = new Child(); child.setName("aaa"); final Marshaller marshaller = JAXBContext.newInstance(ChildDTO.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter stringWriter = new StringWriter(); marshaller.marshal(ChildDTO, stringWriter); String xmlAsString = stringWriter.toString(); XML after Marshall: <child> <parentName> aa </parentName > <childName> aa </ childName > </child>
- Loading branch information