--- On Wed, 2/10/10, Adam Heath <[email protected]> wrote: > From: Adam Heath <[email protected]> > Subject: Re: svn commit: r908713 - in > /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion: > CollectionConverters.java test/MiscTests.java > To: [email protected] > Date: Wednesday, February 10, 2010, 7:05 PM > Adrian Crum wrote: > > Every programmer has their own design style. This > would be mine: > > > > class JsonString { > > public String toString() { > > ... > > } > > } > > > > public static class ListToJsonString<T> extends > AbstractConverter<List<T>, JsonString> { > > public ListToJsonString() { > > super(List.class, JsonString > .class); > > } > > ... > > } > > > > The problem I have with your approach is the fact that > there is no way to know that converting object x to a String > will result in a JSON string. In addition, I was hoping we > could stick to this pattern: Converting any Java type to a > String is the same as calling the object's toString() > method. > > > > -Adrian > > Yeah, I thought you would comment on this. > > Should ListToString and StringToList be reflective? > As they used to > be, they weren't.
That's a good question. The original List conversions were copied from the ObjectType code and I never looked into that code in detail - I just wanted to maintain the original behavior. When I picture java types being converted to strings, I imagine them being displayed - kind of like how they would appear if you did something like: String prompt = "The List is: " + someList; Making the converters reflective is a worthwhile goal - I just never considered it. What you're trying to accomplish is great. We can take that concept even further by having type x to XML converters - so that java objects can be serialized to XML. So, that's why I commented on it. What if I wanted to convert a List to an XML string? Or a [insert encoding method here] string? -Adrian
