为什么在Java中使用marshaller获得小写字符?
我正在尝试整理特定数据以格式化XML文档。我正在使用这个函数:为什么在Java中使用marshaller获得小写字符?,java,xml,jaxb,marshalling,Java,Xml,Jaxb,Marshalling,我正在尝试整理特定数据以格式化XML文档。我正在使用这个函数: public String marshall(EntiteDynamiqueWrapper wrap) throws DocthequeException { JAXBContext jaxbContext; StringWriter sw = new StringWriter(); LOG.debug(wrap.toString()); try { jaxbContext = JA
public String marshall(EntiteDynamiqueWrapper wrap) throws DocthequeException {
JAXBContext jaxbContext;
StringWriter sw = new StringWriter();
LOG.debug(wrap.toString());
try {
jaxbContext = JAXBContext.newInstance(wrap.getCurrentClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
jaxbMarshaller.marshal(wrap.getClassInstance(), sw);
} catch (JAXBException e) {
LOG.error("Error marshalling the entity : " + wrap.getId(), e);
throw new DocthequeException(
"Error marshalling the entity : " + wrap.getId(), e);
}
LOG.debug(sw.toString());
return sw.toString();
}
在第一次LOG.debug时,我得到:
wrapper name : L_COM_ET_CVCM_REFUS_OUV_CPT_PRO
champs du wrapper :
AMT_CVCM_AFF_CODE_BARRE
AMT_DO_CODE_POSTAL_CLIENT
AMT_DO_INTITULE1_ADRESSE_CLIENT
AMT_DO_INTITULE2_ADRESSE_CLIENT
AMT_DO_LIGNE3_ADRESSE_CLIENT
AMT_DO_LIGNE4_ADRESSE_CLIENT
AMT_DO_LIGNE5_ADRESSE_CLIENT
AMT_DO_LIGNE6_ADRESSE_CLIENT
AMT_DO_NO_COMPTE
AMT_DO_VILLE_ADRESSE_CLIENT
AMT_DT_CVCM_CODE_BARRE
AMT_DT_CVCM_DEMATER
AMT_DT_CVCM_TYPEIMP
AMT_DT_ENVIRONNEMENT_CICS
AMT_DT_IDWO
A_COURDEST_CD_TICIV_L028_LO
L_COM_ADRES_BDF_CO
来自marshaller的结果:
预期:
为什么marshal在CD、TICIV、L028、LO和L、COM、ADRES、BDF、CO字段上给我一个小写字母
我注意到,只有在下划线前只有1个字符时,它才会追加。没有问题,该字段的名称为\u COURDEST\u CD\u TICIV\u L028\u LO
感谢大家抽出时间。在EntitedInamiqueWrapper类中尝试以下操作:
@XmlElement( name = "A_COURDEST_CD_TICIV_L028_LO")
private SomeType A_COURDEST_CD_TICIV_L028_LO; // ( or your field A_COURDEST_CD_TICIV_L028_LO);
@XmlElement( name = "L_COM_ADRES_BDF_CO")
private SomeType L_COM_ADRES_BDF_CO;( // Or your field bind to L_COM_ADRES_BDF_CO );
我找到了一个解决办法,使我的字段大写。我刚刚应用了一个正则表达式:
Matcher m = Pattern.compile("<[a-z]_|</[a-z]_").matcher(strToTransform);
StringBuilder sb = new StringBuilder();
int last = 0;
while (m.find()) {
sb.append(strToTransform.substring(last, m.start()));
sb.append(m.group(0).toUpperCase());
last = m.end();
}
sb.append(strToTransform.substring(last));
return sb.toString();
Matcher m=Pattern.compile("marshall之前的字段值是多少。我认为您可能会根据字段值在大写和小写之间切换。@MatíasW的可能重复。marshall之前的值是:“AMT_DT_IDWO A_COURDEST_CD_ticv_L028_LO L_COM_ADRES_BDF_CO”@Marcx关于其他主题,我会检查,但我的字段是动态的,b但也许它不会改变任何事情我想象你有一个声明了所有字段的bean,你应该检查这个/那些类/Esa中的注释正如我之前所说,我的字段是由最终用户动态填充的。这对我来说不是一个好的解决方案,因为这意味着用户不能更改或添加字段。
@XmlElement( name = "A_COURDEST_CD_TICIV_L028_LO")
private SomeType A_COURDEST_CD_TICIV_L028_LO; // ( or your field A_COURDEST_CD_TICIV_L028_LO);
@XmlElement( name = "L_COM_ADRES_BDF_CO")
private SomeType L_COM_ADRES_BDF_CO;( // Or your field bind to L_COM_ADRES_BDF_CO );
Matcher m = Pattern.compile("<[a-z]_|</[a-z]_").matcher(strToTransform);
StringBuilder sb = new StringBuilder();
int last = 0;
while (m.find()) {
sb.append(strToTransform.substring(last, m.start()));
sb.append(m.group(0).toUpperCase());
last = m.end();
}
sb.append(strToTransform.substring(last));
return sb.toString();