java - 在 kotlin 中将 xml(带标签)转换为 tikxml 时出现构建错误
问题描述
我想将带有标签值的 xml 转换为 tikxml。但是失败了。
需要转换的XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resCreateField>
<countryCode mandatory="1">1</countryCode>
<birthDate mandatory="1">1</birthDate>
<policies>
<skipEmailVerification>N</skipEmailVerification>
<require2FactorConfiguration mandatory="1">Y</require2FactorConfiguration>
</policies>
</resCreateField>
我的方法:
@Xml(name = "countryCode")
data class CountryCode(
@PropertyElement(name = "countryCode")
val isCountryCodeMandatory: String? = null,
@Attribute(name = "mandatory")
val countryCodeMandatoryValue: String? = null
)
@Xml(name = "birthDate")
data class BirthDate(
@Attribute(name = "mandatory")
val birthDateMandatoryValue: String? = null,
@PropertyElement(name = "birthDate")
val isBirthDateMandatory: String? = null
)
@Xml(name = "require2FactorConfiguration")
data class Require2FactorConfiguration(
@PropertyElement(name = "require2FactorConfiguration")
val isEmailReceiveYNFlagMandatory: String? = null,
@Attribute(name = "mandatory")
val emailReceiveYNFlagMandatoryValue: String? = null
)
@Xml(name = "policies")
data class Policies(
@PropertyElement(name = "skipEmailVerification")
val skipEmailVerification: String? = null,
@Element(name = "require2FactorConfiguration")
val require2FactorConfiguration: Require2FactorConfiguration
)
@Xml(name = "resCreateField")
data class FieldInfoResponse(
@Element(name = "countryCode")
val countryCode: CountryCode?,
@Element(name = "birthDate")
val birthDate: BirthDate?,
@Element(name = "policies")
val policies: Policies?
)
但我收到以下错误。我找不到原因。
error: The constructor parameter 'isBirthDateMandatory' in constructor
BirthDate(java.lang.String,java.lang.String) in class com.example.utils.server.response.BirthDate is annotated with a TikXml annotation. Therefore a getter method with minimum package visibility with the name getIsBirthDateMandatory() or isBirthDateMandatory() in case of a boolean must be provided. Unfortunately, there is no such getter method. Please provide one!
java.lang.String isBirthDateMandatory)
我对那些没有标签的 xml 使用了 tikxml 。但我无法用标签解决我的情况。
我也检查了这个链接https://github.com/Tickaroo/tikxml/blob/master/docs/AnnotatingModelClasses.md
解决方案
发现了问题。
这里,countryCode 1 的值是一个描述。
<countryCode mandatory="1">1</countryCode>
所以,xml应该这样写
@Xml(name = "countryCode")
data class CountryCode(
@TextContent
val value: String? = null,
@Attribute(name = "mandatory")
val countryCodeMandatoryValue: String? = null
)
推荐阅读
- ansible - "msg": "该任务包含一个带有未定义变量的选项 - 打印一个步骤的输出
- plc - 是否可以向功能块添加静态参数?
- string - 我如何编译这个布尔语句
- c# - 当有太多消息进入时,C# REST 消息处理程序不处理
- angular - 我如何从时刻对象获取输入值
- apache - Apache mod_secure,禁用包含“1---”的cookie规则
- amazon-web-services - Keycloak - 在两个实例之间同步一些用户
- typescript - 如何使用 Typescript 泛型正确映射键和值之间的间接关系?
- flutter - 从另一个小部件访问变量
- java - Eclipse(Luna):生成 WAR 时是否可以获得命令列表?