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

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. #1590

Merged
merged 2 commits into from
Dec 9, 2021

Commits on Oct 13, 2021

  1. 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.
    
    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>
    OritMarkus committed Oct 13, 2021
    Configuration menu
    Copy the full SHA
    40e0826 View commit details
    Browse the repository at this point in the history

Commits on Nov 14, 2021

  1. Configuration menu
    Copy the full SHA
    3b2a01e View commit details
    Browse the repository at this point in the history