logo       

RE: How to declare an array signature in this case?: msg#00107

java.dwr.user

Subject: RE: How to declare an array signature in this case?

Hi Joe,
 
I had a look at the source code and it seems like the org.directwebremoting.extend.Property hierarchy is making it harder to handle generic properties in the correct way. As you are only exposing the raw type from Property, it's hard to use it for looking up actual types. I see you have worked around this in BeanConverter.createTypeHintContext by taking the property's exposed setter method (later using your "getGenericParameterTypesMethod" on it) as this will also reveal the property's actual type, but this is not possible for ObjectConverter as there is no setter.
 
As this is a construct of your own, why not let both BeanConverter and ObjectConverter examine the Property's actual type? That will avoid the indirect way of having to examine the setter and will fix the issue with ObjectConverter...
 
Everything I say here is of course in the context of Java5, where you can examine actual generic types. In my opinion this is not so important to fix for earlier Java versions, especially as that would involve enhancing signatures.
The fix would either be to make it possible to create a TypeHintContext for a field, (not only for a method) from ObjectConverter.createTypeContext, or to simply let the actual generic type be sent into convertInbound of BasicObjectConverter's subclasses, and let them do the inspection themselves...
 
What do you think about this?
 
Best regards
Mike


From: Mike Wilson [mailto:mikewse-PkbjNfxxIARBDgjK7y7TUQ@xxxxxxxxxxxxxxxx]
Sent: den 12 februari 2007 12:39
To: users-EyPigyGktj4FDOXUYO6UHQ@xxxxxxxxxxxxxxxx
Subject: RE: [dwr-user] How to declare an array signature in this case?

Hi Joe,
 
I've had some similar quirks with collection properties lately, so I've done some tests on what you suggest here: 
Did you try this:

<signatures>
import whatever;
void ContainerClass.setElements(Set<ElementClass> s);
</signatures> 
In short, with Java5 and latest DWR from CVS it looks like beans with collection properties are ok without adding signatures, but objects with collection properties are broken even when using signatures. It would be nice to fix this before 2.0.
 
Test setup
 
I'm sending a _javascript_ structure like this to the server:
    var objwithlist = {
        list: [
            {firstName:"Donald", lastName:"Duck", age:72},
            {firstName:"Mickey", lastName:"Mouse", age:79}
        ]
    }
 
public class TestDataTypes {
    public void writeObjectWithList( ObjectWithList data ) { ... }
    public void writeBeanWithList( BeanWithList data ) { ... }
}
 
public class ObjectWithList {
    public List<PersonObject> list;
}
 
public class BeanWithList {
    private List<PersonObject> list;
    public List<PersonObject> getList() { ... }
    public void setList( List<PersonObject> list ) { ... }
}
 
public class PersonObject {
    public String firstName;
    public String lastName;
    public int age;
}
 
<create creator="new" _javascript_="testDataTypes">
    <param name="class" value="TestDataTypes" />
</create>
<convert match="ObjectWithList" converter="object"/>
<convert match="BeanWithList" converter="bean"/>
<convert match="PersonObject" converter="object"/>
 
Results
 
writeObjectWithList:

Wrong: The List<PersonObject> property is set to an ArrayList of String instances where the strings contain "firstName:reference:c0-e3, lastName:reference:c0-e4, age:reference:c0-e5}".

Console: "WARNING: Missing type info for writeObjectWithList(0<0>). Assuming this is a map with String keys. Please add to <signatures> in dwr.xml"

writeBeanWithList:
Correct: The List<PersonObject> is set to an ArrayList containing PersonObject instances.
Signatures
 
I tried adding a signature:
    <signatures>
        <![CDATA[
        import ...
        void ObjectWithList.setList(List<PersonObject> list);
        ]]>
    </signatures>
in case the method signature would be used for the ObjectWithList.list property assignment even though there is no such method, but it doesn't react on this.
 
I can post my test project if you're interested.
 
Best regards
Mike
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise