Closed GoogleCodeExporter closed 9 years ago
This was a difficult, but intentional decision. Why do you want to register a
type adapter for String?
Original comment by limpbizkit
on 2 Feb 2012 at 6:27
sometimes a string can contain data (xml) that have to be handled in a specific
way.
In my scenario, i use xml -> string to serialize an xml via socket between 2
app (and writing them on DB)
xml implementation isn't serializable (so, i have to do a conversion to string)
now, after all the trip (sending data via java serialization, write them on db,
sending results back) i want to dump the result to a js client, that work
better with json.
on 1.7.2 i add a typeadapter that try to detect if a string is an xml (contains
/> or > or something like that, i haven't the code here) and if so, do a custom
serialization before send it out.
Obviusly i can rewrote all the serialization layer, but this will be time
consuming.
What i have found convenient, is to wrap my request/response bean, make the
string that contain xml not gson_able (via notation) and make a getter to write
on the wrapper the XML element that i need.
Then, i use the typeAdapter registered with Xml.Class and make here the custom
serialization.
The only issue is that i have to write more code :(
The other option is to make XML serializable, and this will solve all my issue.
Unfortunatly this solution isn't feasable due to implementation of XML library
(can be probably wrapped as well, with some externalizable stuff, but again is
time consuming)
Original comment by ramarr...@gmail.com
on 6 Feb 2012 at 8:05
Presumably you know which of your strings are eligible to be XML. Create a type
XmlOrString and use that in the appropriate fields. Then register a type
adapter for that type.
class XmlOrString {
Document xml;
String string;
}
Original comment by limpbizkit
on 6 Feb 2012 at 1:42
In your example, XmlOrString isn't serializable (as i state before,
XML /our impl of XML dom/ isn't serializable, due to high resource
need to perform the serialization. Same issue appen on dom4j for
example)
Original comment by ramarr...@gmail.com
on 6 Feb 2012 at 7:00
What does serialization have to do with Gson?
I'm marking this as won't fix just 'cause I don't think your use case is
typical!
Original comment by limpbizkit
on 11 Feb 2012 at 6:30
Original issue reported on code.google.com by
ramarr...@gmail.com
on 1 Feb 2012 at 9:01