java jaxb 解组 xml 数据的默认规则是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5203531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:55:56  来源:igfitidea点击:

what is the default rule for jaxb unmarshall the xml data?

javajaxb

提问by user496949

Want to know, having a class without any annotation, how the jaxb unmarshall the xml data to class.

想知道,有一个没有任何注释的类,jaxb 是如何将 xml 数据解组到类的。

I found it can take the following

我发现它可以采取以下措施

If I have an node "label" in the xml

如果我在 xml 中有一个节点“标签”

I have "_label" field in the class and "getLabel" and "setLabel" method.

我在类中有“_label”字段以及“getLabel”和“setLabel”方法。

jaxb can unmarshall it sucsessully. Just want to know its default rule.

jaxb 可以成功解组它。只想知道它的默认规则。

回答by bdoughan

The following is from the JAXB 2 specification (JSR-222):

以下内容来自 JAXB 2 规范 ( JSR-222):

8.12 Default Mapping

This section describes the default mapping of program elements. The default mapping is specified in terms of default annotations that are considered to apply to a program element even in their absence.

8.12.1 Java Identifier To XML Name

The following is the default mapping for different identifiers:

  • class name: a class name is mapped to an XML name by de capitalization using java.beans.Introspector.decapitalize(class name ).
  • enumtype name: enumtype name is mapped to an XML name by de capitalization using java.beans.Introspector.decapitalize(enumtype name).
  • A property name (e.g. address) is derived from JavaBean access method (e.g. getAddress) by JavaBean de capitalization of the JavaBean property name java.beans.Introspector.decapitalize(JavaBeanAcc essMethod)

8.12 默认映射

本节介绍程序元素的默认映射。默认映射是根据默认注释指定的,即使在它们不存在的情况下,这些注释也被认为适用于程序元素。

8.12.1 XML 名称的 Java 标识符

以下是不同标识符的默认映射:

  • 类名:类名通过使用 java.beans.Introspector.decapitalize(class name ) 去大写映射到 XML 名称。
  • enumtype name:enumtype name 使用 java.beans.Introspector.decapitalize(enumtype name) 通过去大写映射到 XML 名称。
  • 属性名称(例如地址)是通过 JavaBean 对 JavaBean 属性名称 java.beans.Introspector.decapitalize(JavaBeanAcc essMethod) 的大写从 JavaBean 访问方法(例如 getAddress)派生而来的