Spider Strategies Blog

The latest news about our company and software

Easily convert and copy information using Morph

Matt Sgarlata, May 21, 2007

Ever since I first got started programming and was exposed to different computer languages I've been annoyed at how difficult it is to convert information from one type to another. Not only does every language have its own way of doing this, often even within the same language there are multiple different methods that need to be learned to do conversions properly. I can't offer a solution for every programming language, but I can offer a solution for Java: the Morph framework. The main goal of Morph is to make it really easy to take information in one format and make it available in another format. I am including some examples along with this article to show how easy it is to do all sorts of conversions with Morph. You can get a full list of the conversions that come out of the box here.

Morph.convert allows you to convert an object from one type to another. Here are some examples:

Morph.copy allows information from one object to be copied to another object. The object to which information is copied may even be of a different type than the source object. A great example of when you need to do this type of thing is when you need the data in an HttpServletRequest to be available to lower tiers in your application but you don't want to tie your entire application to the servlet API. For example, let's say you are trying to get your data prepared for a method with a signature IServiceInterface.service(Map data):