What’s the simplest way to serialize a bean to a string using GWT? I prefer not to use GWT.create() invocations.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Disclaimer: Serializing a bean on the URL isn’t such a great idea for GWT. I’ve learned that if need to put data on the URL, it should be as little as possible and only what is necessary to restore the state of your page. Look at how Gmail uses its history tokens and you’ll see it is pretty minimal.
With that disclaimer out of the way:
For a GWT project I worked on I simply wrote out values of the bean separated by a delimiter. When reading the values back in, I used the String.split() method to get an array. With that array I assign the values back to the right bean properties. In code:
For more complicate scenarios you may have to do more complicated things. For example, for nested objects, you have to write the code to pass the values to the child object(s).
Also, be aware that you have to make sure that any values you use don’t contain the delimiter. So if you know your Strings might contain ‘/’ then you might have to do a replace() operation of them to escape any nested delimiters.