Open Shinryuken opened 7 years ago
The JAXB Setters Plugin will modify the behavior of generation to generate setters for lists.
If you're not able to correct the generation, here is some code I wrote awhile back to address this problem for lists of Strings:
public static class ElementPropertyResolver extends IntrospectorPropertyResolver
{
private static final Type<?> STRING_LIST_TYPE = TypeFactory.valueOf(List.class, String.class);
@Override
protected Property getProperty(java.lang.reflect.Type type,
String expr,
boolean isNestedLookup,
Property owner) throws MappingException
{
try
{
return super.getProperty(type, expr, isNestedLookup, null);
}
catch (MappingException e)
{
try
{
Type<?> genericType = TypeFactory.valueOf(type);
String getter = "get" + StringUtils.capitalize(expr) + "()";
Property property = Property.Builder.propertyFor(genericType, expr)
.type(STRING_LIST_TYPE).getter(getter).setter(getter).build(this);
return new ListAddAllProperty(property);
}
catch (MappingException e2)
{
throw e; // throw the original exception
}
}
}
}
private static class ListAddAllProperty extends Property
{
public ListAddAllProperty(Property property)
{
super(property.getExpression(),
property.getName(),
property.getGetter(),
property.getSetter() + ".addAll(%s)",
property.getType(),
property.getElementType(),
property.getContainer());
}
}
And to register it:
new DefaultMapperFactory.Builder().propertyResolverStrategy(new ElementPropertyResolver())
Hi, i'm having a hard time trying to map a flat entity with a nested Jaxb generated structure.
I did not found a method to change the behaviour of the xsd generator, it will create those strange case issues between fields names and getters/setters method names, it's creating wrapper classes for multioccurence elements too with only the getter logic, i noticed the ScoringClassMapBuilder example on the test packages but i keep getting errors, i could change eventually the flat entity field names if necessary (the flat entity was made using all the leaf fields of the nested structure), this is an example with the same structure of the project:
(you can find all the classes attached)
I'm sorry if this is not the right place to ask, thanks in advance.
flat_jaxb_orika.zip