GWT AutoBean with POJO class instead of interface

后端 未结 2 769
梦谈多话
梦谈多话 2021-01-17 09:55

I\'m hoping someone can suggest a simple solution to my problem.

I have a POJO, say:

public class Person
{
    private String name;
    public String         


        
相关标签:
2条回答
  • 2021-01-17 09:56

    It is possible if its a simple POJO and does not have properties of other autobean types:

    1) Make PersonPojo implements Person

    2) Add a wrapper method to the factory:

    public interface PersonFactory extends AutoBeanFactory {
        AutoBean<Person> person( Person p ); // wrap existing
    }
    

    3) Create wrapped AutoBean and serialise with AutoBeanCodex.encode to JSON

    PersonPojo myPersonPojo = new PersonPojo("joe");
    AutoBean<Person> autoBeanPerson = personFactory.person( myPersonPojo );
    
    0 讨论(0)
  • 2021-01-17 10:03

    You simply can't. AutoBean generates lightweight, optimized implementations of the interfaces; it obviously cannot do this for classes. This is by design.

    0 讨论(0)
提交回复
热议问题