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

Conversation

OritMarkus
Copy link
Contributor

DTOs:

@XmlRootElement(name = "parent")
public class ParentDTO {
	Protected String name;
	
    @XmlElement(name= “parentName”)
    public String getName() {
        return name;
    }

     public void setName(String name) {
        this.name = name;
    }
}



@XmlRootElement(name = "child")
public class ChildDTO extends ParentDTO {
	
   @Override
   @XmlElement(name="childName")
    public String getName() {
        return name;
    }
}

Program:

ChildDTO child = new ChildDTO();
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>

…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
Copy link
Contributor Author

OritMarkus commented Nov 14, 2021

Any chance to get a new version that contains this patch soon?
It is very important for us. We cannot use all version after 2.2.6
@lukasj @Tomas-Kraus @keilw @tvallin @eclipse-jaxb-impl-bot

@OritMarkus
Copy link
Contributor Author

Can you help me guys?
@lukasj @Tomas-Kraus @keilw @tvallin @eclipse-jaxb-impl-bot

It is very important for us. We cannot use all version after 2.2.6

Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

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

LGTM; I'll add a test for this myself. Thx!

@lukasj lukasj merged commit be6d4fd into eclipse-ee4j:master Dec 9, 2021
lukasj added a commit to lukasj/jaxb-ri that referenced this pull request Dec 9, 2021
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit that referenced this pull request Dec 9, 2021
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
@OritMarkus
Copy link
Contributor Author

OritMarkus commented Dec 13, 2021

@lukasj Any idea when the new release will be available?

@OritMarkus
Copy link
Contributor Author

@lukasj Hi, Do you know when the new release with this changes will be available?

@lukasj
Copy link
Member

lukasj commented Jan 20, 2022

In which version do you need the fix? 2.3.x (javax namespace) or 3.0.x (jakarta namespace)?

@OritMarkus
Copy link
Contributor Author

OritMarkus commented Jan 20, 2022

@lukasj We are working with javax namespace
Is there any chance that a new version will come out soon?

@OritMarkus
Copy link
Contributor Author

@lukasj Do you have an indication as to when this will happen?

@lukasj
Copy link
Member

lukasj commented Jan 25, 2022

likely this week, as to which day exactly - I don't know, there few more pending tasks on my list

lukasj pushed a commit to lukasj/jaxb-ri that referenced this pull request Jan 27, 2022
…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. (eclipse-ee4j#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>

(cherry picked from commit be6d4fd)
lukasj added a commit to lukasj/jaxb-ri that referenced this pull request Jan 27, 2022
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit db536c9)
lukasj pushed a commit that referenced this pull request Jan 27, 2022
…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>

(cherry picked from commit be6d4fd)
lukasj added a commit that referenced this pull request Jan 27, 2022
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit db536c9)
@lukasj
Copy link
Member

lukasj commented Jan 27, 2022

can you check https://jakarta.oss.sonatype.org/content/repositories/staging/com/sun/xml/bind/jaxb-ri/2.3.6/jaxb-ri-2.3.6.zip (or through https://jakarta.oss.sonatype.org/content/repositories/staging maven repo) and let me know the problem is fixed there? just to double check it before the binary gets published to central...

@OritMarkus
Copy link
Contributor Author

@lukasj looks great!!

@lukasj
Copy link
Member

lukasj commented Jan 28, 2022

thanks for checking; it will appear in central today (in an hour or two)

@OritMarkus
Copy link
Contributor Author

@lukasj Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants