0

I struggle with request factory in gwt. I can make it work with Generics and Polymorphic classes. See here:

RequestFactory client-side inheritance of typed class with generics

Gwt Request Factory. Generics and Inheritance on client side

RequestFactory Entity's parameter: List<OfOtherEntity> is null on client. On server is ok

I think about to switch to restygwt as a transportation layer. This a new app, so there is not much to rewrite. I thought that RF will suit my needs, unfortunatelly I couldn't make it work. So I am thinking about Resty.

Please tell me would it work with generics and polymorphic classes like this below:

@MappedSuperclass
public  class GenericModel<T extends GenericModel<T>> implements Identifiable, Versionable {
    getId();
    getVersion();
}

@MappedSuperclass
public abstract class GenericDictionaryModel<T extends GenericModel<T>> extends GenericModel<T> {        getName();
    getActive();
}

@Entity class VocabularyDictionaryModel extends GenericDictionaryModel {
    someCustomeMethod();
}


public class GenericDao<T extends GenericModel<T>> {
    public List<GenericModel<T>> getList() {
        return JPA.em().createQuery("FROM " + entityClass.getSimpleName()).getResultList();
    }
}



public class GenericDictionaryDao<T extends GenericDictionaryModel<T>> extends GenericDao<T>{
    public List<GenericDictionaryModel<T>> getListOrderedByName() {
        try {
            return JPA.em()
                      .createQuery("FROM " + entityClass.getSimpleName() + " ORDER BY name")
                      .getResultList();
        } catch (ClassCastException e) {
            return new LinkedList<GenericDictionaryModel<T>>();
        }
    }
}
masterdany88
  • 5,041
  • 11
  • 58
  • 132
  • Out of curiosity what problem are you still having with RF? Is there an error? From looking at your other questions I have a feeling you are running into a problem that I had where the method cannot be invoked unless it is declared in the RequestContext for the child entity type. Meaning if you extend GenericContext you have to add the method again in the child RequestContext interface. This is extra work but it allowed me to use the GenericContext as a when I wanted to make code clean. – Chris Hinshaw Dec 01 '15 at 18:31
  • I would like to avoid code repetition. I am schocked that generic doesn't work out of box. I still struggle with RF. – masterdany88 Dec 01 '15 at 19:51

1 Answers1

0

Yes you should not have a problem using generics with Resty. You will have to play with the Jackson annotations a bit to get them right for inheritence. Mainly the @JsonSubTypes and @JsonTypeName.

Keep in mind that you will have to handle error handing more or less yourself. There is quite a bit more code to get the rest application working than rf but IMHO it makes your API more portable fore more platform types.

Here is an example of what you are asking. I have used the unit tests quite often to solve some edge cases.

https://github.com/resty-gwt/resty-gwt/blob/master/restygwt/src/test/java/org/fusesource/restygwt/client/basic/ParameterizedTypeDTO.java

Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65