如何防止JAXB转义字符串 [英] How to prevent JAXB escaping a string

查看:559
本文介绍了如何防止JAXB转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由XJC生成的对象,名为 Product 。我想将 product.currentPrice(一个字符串)设置为& amp;#x00A3; 210 其中& amp;#x00A3; 是货币符号(从系统的其他地方传入)。

I have an object, generated by XJC, called Product. I want to set product.currentPrice (a String) to be £210 where £ is the currency symbol (passed in from elsewhere in the system).

麻烦的是, JAXB正在逃离我的&号,因此它产生& amp; amp;#x00A3; 210 。我如何使它不这样做?

Trouble is, JAXB is escaping my ampersand, so it produces £210 instead. How do I make it not do this?

推荐答案

默认情况下,JAXB的marshaller实现通常会转义字符。要更改此默认行为,您必须编写一个实现 com.sun.xml.bind.marshaller.CharacterEscapeHandler 接口的类。

By default, the marshaller implementation of the JAXB usually escapes characters. To change this default behavior you will have to Write a class that implements the com.sun.xml.bind.marshaller.CharacterEscapeHandler interface.

在Marshaller中设置该处理程序

set that handler in the Marshaller

CharacterEscapeHandler escapeHandler = NoEscapeHandler.theInstance;
marshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", escapeHandler); 

您可以查看JAXB提供的样本,字符转义样本

You can have a look at samples provided with JAXB, character escaping sample

这篇关于如何防止JAXB转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆