Comments (1)
Hi @kevinsdooapp,
sorry for the late reply.
I've reviewed your suggestion, thought it over and came to the conclusion that this can be already covered by the existing infrastructure. I don't think there is a need for another plugin.
The goal is to be able to customize, how enum is turned to string, this can already be done in the strategy. For instance, consider we want to print out value of the enum instead of its name. Here's our enum:
@XmlType(name = "issueGH31Type")
@XmlEnum
public enum IssueGH31Type
implements EnumValue<String>
{
@XmlEnumValue("Male")
MALE("Male"),
@XmlEnumValue("Female")
FEMALE("Female");
private final String value;
IssueGH31Type(String v) {
value = v;
}
public String value() {
return value;
}
public static IssueGH31Type fromValue(String v) {
for (IssueGH31Type c: IssueGH31Type.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
public String enumValue() {
return this.value();
}
}
In the strategy we can just implement the append
method to check if the value is instance of EnumValue
and use the value of the enum to convert it to string:
final ToStringStrategy2 s = new JAXBToStringStrategy() {
// ...
public StringBuilder append(ObjectLocator locator,
StringBuilder buffer, Object value) {
if (value instanceof EnumValue<?>) {
return super.append(locator, buffer,
((EnumValue<?>) value).enumValue());
} else {
return super.append(locator, buffer, value);
}
};
};
This produces Male
/Female
instead of MALE
/FEMALE
for IssueGH31Type
.
You can argue whether instanceof
is good or not, but that'd be better solved with the visitor pattern, making enums implement ToString
won't help much with that.
Enums don't need to implement the ToString
interface because they are atomic values. And it's the responsibility of the strategy to decide how individual values should be converted to strings.
So I don't see any necessity for enums to implement ToString
.
Accordingly I'm intending to close this issue and the pull request #32 as wontfix
. I'd be grateful to know what you think, if maybe I'm missing something.
And thank you for your effort. I am sorry it took me so long to et to this issue.
Best wishes,
Alexey
from jaxb2-basics.
Related Issues (20)
- Update build to use maven release plugin
- Reverting jakarta initial changes HOT 1
- Update to latests jaxb v2.x
- Update to JUnit 4.13.2
- Upgrade to commons-io 2.11.0
- Update to JDK 1.8 minimum for source and target
- Add support for building with JDK 9+
- Update maven scm for release automation
- Bump version to 0.13.0-SNAPSHOT
- Fix maven-deploy-plugin / oss-staging-plugin fighting each other
- Update version to 2.3.6-SNAPSHOT
- Migrate to jakarta.oss.sonatype.org HOT 1
- Take over the remaining jaxb2_commons plugins HOT 11
- Bump commons-beanutils HOT 10
- Jakarta classes support for jaxb2-basics HOT 20
- Simplifying element (rather than type) results in 'Unable to honor this as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings.'. HOT 1
- Possibilty to find a fix for fixedValues in ComplexType restriction
- Prepare migration to jakarta HOT 1
- Is the latest release published on Maven Repository? HOT 6
- Other xjc plugins repository - maybe useful source code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxb2-basics.