highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
108 stars 54 forks source link

Is there any way to generate short class names from toString? #76

Closed jbek7 closed 7 years ago

jbek7 commented 7 years ago

Hello, The plugin is working fine but am not able to find a way to configure ToString Style (like apache-commons ToStringBuilder) or is there any documentation on it?

Thanks!

jbek7 commented 7 years ago

Never mind... I was able to create it by extending DefaultToStringStrategy Posting the code in case some also needs it:

public class SimpleToStringStrategy extends DefaultToStringStrategy {

    @Override
    public boolean isUseIdentityHashCode() {
        return false;
    }
    @Override
    protected void appendClassName(StringBuilder buffer, Object object) {
        if (object != null) {
            buffer.append(getShortClassName(object.getClass()));
        }
    }
}
highsource commented 7 years ago

Yes, strategy is the way to go. You can also configure it to be the default strategy when generating code.