[#7579] [#8044] Code generation fails on JDK9+ with javax.xml.bind.UnmarshalException: unexpected element when using external <configurationFile/>
This commit is contained in:
parent
c2029a434c
commit
8197c65fbb
@ -90,6 +90,7 @@ import org.jooq.meta.jaxb.Target;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
|
||||
|
||||
/**
|
||||
@ -925,6 +926,10 @@ public class GenerationTool {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// [#7579] [#8044] Workaround for obscure JAXB bug on JDK 9+
|
||||
xml = MiniJAXB.jaxbNamespaceBugWorkaround(xml, new InformationSchema());
|
||||
|
||||
return (Configuration) unmarshaller.unmarshal(new StringReader(xml));
|
||||
}
|
||||
catch (Throwable t) {
|
||||
|
||||
@ -243,18 +243,10 @@ public class XMLDatabase extends AbstractDatabase {
|
||||
"<information_schema>",
|
||||
"<information_schema xmlns=\"" + Constants.NS_META + "\">");
|
||||
|
||||
// [#7579] On JDK 9, 10, depending on how JAXB is loaded onto the classpath / module path,
|
||||
// the xmlns seems to be considered for (un)marshalling, or not. This seems to be
|
||||
// a bug in JAXB, with no known tracking ID as of yet.
|
||||
// The following quick fix tests the presence of the xmlns when marshalling, and if absent
|
||||
// removes it prior to unmarshalling.
|
||||
StringWriter test = new StringWriter();
|
||||
// [#7579] [#8044] Workaround for obscure JAXB bug on JDK 9+
|
||||
content = MiniJAXB.jaxbNamespaceBugWorkaround(content, new InformationSchema());
|
||||
|
||||
try {
|
||||
JAXB.marshal(new InformationSchema(), test);
|
||||
|
||||
if (!test.toString().contains("xmlns"))
|
||||
content = content.replaceAll("xmlns=\"[^\"]*\"", "");
|
||||
|
||||
info = JAXB.unmarshal(new StringReader(content), InformationSchema.class);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
|
||||
@ -43,6 +43,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@ -314,4 +315,26 @@ public class MiniJAXB {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used internally by jOOQ to patch XML content in order to
|
||||
* work around a bug in JAXB.
|
||||
* <p>
|
||||
* [#7579] [#8044] On JDK 9, 10, depending on how JAXB is loaded onto the
|
||||
* classpath / module path, the xmlns seems to be considered for
|
||||
* (un)marshalling, or not. This seems to be a bug in JAXB, with no known
|
||||
* tracking ID as of yet.
|
||||
* <p>
|
||||
* The following quick fix tests the presence of the xmlns when marshalling,
|
||||
* and if absent removes it prior to unmarshalling.
|
||||
*/
|
||||
public static String jaxbNamespaceBugWorkaround(String xml, Object annotated) {
|
||||
StringWriter test = new StringWriter();
|
||||
JAXB.marshal(annotated, test);
|
||||
|
||||
if (!test.toString().contains("xmlns"))
|
||||
xml = xml.replaceAll("xmlns=\"[^\"]*\"", "");
|
||||
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user