Why does JAXB need a no arg constructor for marshalling?

前端 未结 4 912
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 18:02

If you try to marshal a class which references a complex type that does not have a no-arg constructor, such as:

import java.sql.Date;

@XmlRootElement(name =         


        
4条回答
  •  一个人的身影
    2020-12-04 18:13

    You seem to be under the impression that the JAXB introspection code will have action specific paths for initialization. if so, that would result in a lot of duplicate code and would be a poor implementation. i would imagine that the JAXB code has a common routine which examines a model class the first time it is needed and validates that it follows all the necessary conventions. in this situation, it is failing because one of the members does not have the required no-arg constructor. the initialization logic is most likely not marshall/unmarshall specific and also highly unlikely to take the current object instance into account.

提交回复
热议问题