This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XMLDecoder doesn't ignore whitespace?  RSS feed

 
Philippe Desrosiers
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted this in the "Servlets" forum, but the post seems to have disappeared, so here it is again (hopefully in the right place this time):

I'm trying to deserialize some Objects stored using an XMLEncoder. Specifically, I have a "MyClassObserver" class that has an "instanceClass" field of type java.lang.Class.
The XMLDecoder can't load classes specified in the xml, because (I think) of whitespace. so, something like this:


will always pop an exception like this:

Notice all the whitespace in the stack trace? I think the ClassLoader (or the XMLDecoder) isn't trimming the class name before trying to load it. Any suggestions?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's significant whitespace you have around the class name, so XML software isn't going to trim it off for you. And if the classloader doesn't trim it (as the stack trace suggests is the case) then it's up to you to trim it yourself. Or if there isn't anything in your code that can get access to it, then don't put the whitespace in the XML in the first place.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!