Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeConverter not running for strings of type Object #32

Open
kpentaris opened this issue Feb 5, 2020 · 0 comments
Open

TypeConverter not running for strings of type Object #32

kpentaris opened this issue Feb 5, 2020 · 0 comments

Comments

@kpentaris
Copy link

kpentaris commented Feb 5, 2020

When declaring a TypeConverter, it properly runs if the Java field is of type String but if it is of type Object in which case XStream puts the runtime type in a class attribute, the TypeConverter never runs.

The problem is in the MappedXMLStreamWriter.JSONPropertyObject class in the withProperty method as well as in MappedXMLStreamWriter.JSONPropertyString.
Current implementation:

Object value = property.getValue();
if (add && value instanceof String) {
  value = this.convention.convertToJSONPrimitive((String)value);
}

Suggested implementation idea (needs exception handling etc):

Object value = property.getValue();
if (add && value instanceof String) {
  value = this.convention.convertToJSONPrimitive((String)value);
} else if (add && value instanceof JSONObject && "string".equals(value.get("@class"))) {
  value.put("$",  this.convention.convertToJSONPrimitive((String)value.get("$")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant