What JAXB needs a public no-arg constructor for?

后端 未结 3 764
忘了有多久
忘了有多久 2020-12-09 09:26

What does JAXB need a public no-arg constructor for, during marshalling?

 Marshaller msh = ctx.createMarshaller();
 msh.marshal(object, System.out);
         


        
3条回答
  •  独厮守ぢ
    2020-12-09 10:11

    As others have noted, it shouldn't really need one but (at least in Sun's implementation) it does. You can get around this with a dummy constructor:

    private MyObject() {
        throw new UnsupportedOperationException("No-arg constructor is just to keep JAXB from complaining");
    }
    

提交回复
热议问题