You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
If you try with java.util.List, it will work but will have raw type warnings.
However, this is not as simple as stripping out the generics. Its entirely
possible that it could be a list of some custom element, and thus that custom
element needs to be imported as well. It could also be a Map, and thus have
multiple generic parameters, or a list of maps, so the solution needs to handle
that. (Ex: Map<String, Map<String, List<String, OtherType<String, Map<String,
String>, String>>>> ..)
I wrote up a fix Someone just needs to figure out where it needs to go,
refactor it to fit JAXB coding conventions, and possibly add some sensible error
messages that can be passed to the user.
final Set imports = new TreeSet();
final Matcher typeMatcher = Pattern.compile("[^<>,
p
{Blank}
]+").matcher(name);
final StringBuffer sb = new StringBuffer();
while (typeMatcher.find()) {
final String qualifiedType = typeMatcher.group().trim();
if (qualifiedType.isEmpty())
{ break; }
final int endIndex = qualifiedType.lastIndexOf(".");
if (endIndex < 0)
When the type being mapped to is generic, xjc does not strip generics off of the
import statement.
Example:
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
<xjc:javaType adapter="ListAdapter" name="java.util.List" />
generates to
import java.util.List; // <-- Problem
import javax.xml.bind.annotation.XmlAccessType;
*
*
*
@xmlelement(type = String.class)
@XmlJavaTypeAdapter(ListAdapter.class)
protected Listitems;
*
*
*
If you try with java.util.List, it will work but will have raw type warnings.
However, this is not as simple as stripping out the generics. Its entirely
possible that it could be a list of some custom element, and thus that custom
element needs to be imported as well. It could also be a Map, and thus have
multiple generic parameters, or a list of maps, so the solution needs to handle
that. (Ex: Map<String, Map<String, List<String, OtherType<String, Map<String,
String>, String>>>> ..)
I wrote up a fix Someone just needs to figure out where it needs to go,
refactor it to fit JAXB coding conventions, and possibly add some sensible error
messages that can be passed to the user.
final Set imports = new TreeSet();
final Matcher typeMatcher = Pattern.compile("[^<>,
p
{Blank}
]+").matcher(name);
final StringBuffer sb = new StringBuffer();
while (typeMatcher.find()) {
final String qualifiedType = typeMatcher.group().trim();
if (qualifiedType.isEmpty())
{ break; }
final int endIndex = qualifiedType.lastIndexOf(".");
if (endIndex < 0)
{ typeMatcher.appendReplacement(sb, qualifiedType); }
else
{ imports.add(qualifiedType); // Might want to do error checking ("name = java.util.") final String type = qualifiedType.substring(endIndex + 1); typeMatcher.appendReplacement(sb, type); }
}
typeMatcher.appendTail(sb);
final String javaType = sb.toString();
Environment
Operating System: All
Platform: All
Affected Versions
[2.1.12]
The text was updated successfully, but these errors were encountered: