JAXB and constructors

前端 未结 4 541
温柔的废话
温柔的废话 2020-12-04 12:28

I\'m starting learning JAXB, so my question can be very silly. Now I have classes and want generate XML Schema. Going after this instruction I get exception

4条回答
  •  萌比男神i
    2020-12-04 13:21

    JAXB re-creates beans from XML in a simple fashion : it creates a new instance of the bean, and then do all the setXXX needed to set the attributes. So, if your bean doesn't have a no-args constructor, JAXB can't create it. As said in other answers, JAXB works better for simple "container" beans, for which no-args constructor isn't really a problem. If you're trying to create beans that need specific initialization, you'll need to do it in the setXXX methods.

提交回复
热议问题