Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Unmarshalling xml contents with own namespace results in null fields. #1180

Open
LanceAndersen opened this issue Apr 20, 2018 · 0 comments
Open

Comments

@LanceAndersen
Copy link

Previously tracked as https://bugs.openjdk.java.net/browse/JDK-8191965

FULL PRODUCT VERSION :
1.8.0_152

ADDITIONAL OS VERSION INFORMATION :
OS X EL Capitan 10.11.1

A DESCRIPTION OF THE PROBLEM :
when I tried to unmarshal xml contents with its own namespace, every field in a tag with the namespace is null. But, with jdk version 1.8.0_101 it works without any trouble.
For example, unmarshalling the xml into the java class below, you can see the id value is "foo" with jdk version 1.8.0_101 but is null with 1.8.0_152.

foo

public class Message {

public Result result; 

public static class Result { 
    public String id; 
} 

}

I found the source code of [com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader] has been changed a little bit. Because of the difference of method name of the [childElement], [UnmarshallingContext] works with [com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader] in 1.8.0_101, but [com.sun.xml.internal.bind.v2.runtime.unmarshaller.Discarder] in 1.8.0_152 when starting to unmarshal the tag with namespace.

I'm not sure whether you intended this, but the thing is working differently depending on the jdk version.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just unmarshal the xml into the java class below.
It works differently depending on jdk version. (1.8.0_152, 1.8.0_101)

foo

public class Message {

public Result result; 

public static class Result { 
    public String id; 
} 

}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
jdk version 1.8.0_101 -> result.id = "foo"
ACTUAL -
jdk versoin 1.8.0_152 -> result.id = null

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error message.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
@test
public void unmarshal_with_xml_including_namespace() {
String xml = "<message type="response" version="1.0.0"><result xmlns="com.naver.com">foo";

    Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 
    jaxb2Marshaller.setClassesToBeBound(Message.class); 

    Source source = new StreamSource(new StringReader(xml)); 
    Message result = (Message) jaxb2Marshaller.unmarshal(source); 

    assertThat(result.result.getId(), is(nullValue())); 
} 

---------- END SOURCE ----------

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

No branches or pull requests

1 participant