2015-11-02 53 views
0
public class ResposneMessage { 

    private int status; 
    private String code = ""; 
    private String message = ""; 
    private Object data; 
} 

的 “DictType” 不封:JAXB -EclipseLink莫西对象类型没有得到正确整理

{ 
    "code": "", 
    "data": "[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]", 
    "message": "", 
    "status": 200 
} 

默认是不封送Object类型。

+0

这是重复的 - 请参阅这里 - http://stackoverflow.com/questions/818327/jaxb-how-should-i-marshal-complex-nested-data-structures – kinshuk4

+0

@ kinshuk4除非那根本不是重复的但是完全不同的问题。 – PureSpider

回答

0

无法将Object编组为任何有意义的JSON表示,因为负责编组对象的库使用反射来执行此操作。它似乎只查看您定义的层次结构中最顶级的类,并收集它在其中找到的任何内容。 由于Object没有任何内容,因此您只需要获得.toString()表示形式。

FWIW:当您尝试编组接口或(抽象)超类时发生同样的情况。您只能在编组输出中看到interface/superclass自身定义的属性 - 无论子类声明/定义什么。 拿这个例子:

public class SuperClass { 
} 

public class OtherClass extends SuperClass { 
    public String someProperty = "test"; 
} 

public class MarshallMe { 
    public SuperClass classTest = new OtherClass(); 
} 

这马歇尔刚刚"classTest":{},因为SuperClass没有任何自己的属性。

+0

谢谢,但我怎样才能使用Moxy做到这一点。因为宁静的结果是Object,所以可以返回不同的结果。我们现在使用Jackson的ObjectMapper来生成json。 –

相关问题