GWT AutoBean with POJO class instead of interface

后端 未结 2 794
梦谈多话
梦谈多话 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 p ); // wrap existing
    }
    

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

    PersonPojo myPersonPojo = new PersonPojo("joe");
    AutoBean autoBeanPerson = personFactory.person( myPersonPojo );
    

提交回复
热议问题