Java JAXB marshaller changes encoding of Can I force JAXB not to convert " into ", for example, when marshalling to XML?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
Plot of a tornado-shaped surface
What is going on with 'gets(stdin)' on the site coderbyte?
Why is so much work done on numerical verification of the Riemann Hypothesis?
Can disgust be a key component of horror?
Mimic lecturing on blackboard, facing audience
Using substitution ciphers to generate new alphabets in a novel
How do you make your own symbol when Detexify fails?
Can I say "fingers" when referring to toes?
Why is it that I can sometimes guess the next note?
Why is the "ls" command showing permissions of files in a FAT32 partition?
Pre-mixing cryogenic fuels and using only one fuel tank
On a tidally locked planet, would time be quantized?
Do the primes contain an infinite almost arithmetic progression?
Does the Linux kernel need a file system to run?
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
creating a ":KeepCursor" command
Does the UK parliament need to pass secondary legislation to accept the Article 50 extension
Are Captain Marvel's powers affected by Thanos' actions in Infinity War
Why does the Sun have different day lengths, but not the gas giants?
Picking the different solutions to the time independent Schrodinger eqaution
Can I still be respawned if I die by falling off the map?
Why is this estimator biased?
Did arcade monitors have same pixel aspect ratio as TV sets?
Why would a new[] expression ever invoke a destructor?
Java JAXB marshaller changes encoding of
Can I force JAXB not to convert " into ", for example, when marshalling to XML?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
having
String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);
JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();
having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node
generates
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
expectation is:
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
JavaEE 7.
java jaxb tags
add a comment |
having
String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);
JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();
having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node
generates
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
expectation is:
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
JavaEE 7.
java jaxb tags
2
What is your question? The>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.
– f1sh
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday
add a comment |
having
String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);
JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();
having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node
generates
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
expectation is:
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
JavaEE 7.
java jaxb tags
having
String translationXsd = TranslationPropertyHelper.getFileLocation(PropertyKey.TRANSLATE_XSD_FILE);
File translationXsdFile = new File(translationXsd);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(translationXsdFile);
JAXBContext jaxbContext = JAXBContext
.newInstance(translationJob.getClass().getPackage().getName());
Marshaller marshaller = jaxbContext.createMarshaller();
OutputStream os = new FileOutputStream(pOutputFile);
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(os));
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, translationXsdFile.getName());
marshaller.setSchema(schema);
marshaller.marshal(translationJob, xsw);
xsw.close();
having a freetext, e.g. "hello i have < b > bold < / b > text inside." in node
generates
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
expectation is:
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
JavaEE 7.
java jaxb tags
java jaxb tags
asked yesterday
PdMPdM
395
395
2
What is your question? The>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.
– f1sh
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday
add a comment |
2
What is your question? The>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.
– f1sh
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday
2
2
What is your question? The
>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.– f1sh
yesterday
What is your question? The
>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.– f1sh
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday
add a comment |
1 Answer
1
active
oldest
votes
You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler
. From JavaDoc
:
Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.
Simple example how to use it:
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;
public class JaxbApp
public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();
PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);
@XmlRootElement(name = "freetextnode")
class FreeTextNode
private String value;
@XmlValue
public String getValue()
return value;
public void setValue(String value)
this.value = value;
Above code prints:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
See also:
- Can I force JAXB not to convert " into ", for example, when marshalling to XML?
- DumbEscapeHandler
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280620%2fjava-jaxb-marshaller-changes-encoding-of-but-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler
. From JavaDoc
:
Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.
Simple example how to use it:
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;
public class JaxbApp
public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();
PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);
@XmlRootElement(name = "freetextnode")
class FreeTextNode
private String value;
@XmlValue
public String getValue()
return value;
public void setValue(String value)
this.value = value;
Above code prints:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
See also:
- Can I force JAXB not to convert " into ", for example, when marshalling to XML?
- DumbEscapeHandler
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
add a comment |
You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler
. From JavaDoc
:
Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.
Simple example how to use it:
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;
public class JaxbApp
public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();
PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);
@XmlRootElement(name = "freetextnode")
class FreeTextNode
private String value;
@XmlValue
public String getValue()
return value;
public void setValue(String value)
this.value = value;
Above code prints:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
See also:
- Can I force JAXB not to convert " into ", for example, when marshalling to XML?
- DumbEscapeHandler
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
add a comment |
You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler
. From JavaDoc
:
Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.
Simple example how to use it:
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;
public class JaxbApp
public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();
PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);
@XmlRootElement(name = "freetextnode")
class FreeTextNode
private String value;
@XmlValue
public String getValue()
return value;
public void setValue(String value)
this.value = value;
Above code prints:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
See also:
- Can I force JAXB not to convert " into ", for example, when marshalling to XML?
- DumbEscapeHandler
You need to merge marshalling with com.sun.xml.internal.bind.marshaller.DumbEscapeHandler
. From JavaDoc
:
Escape everything above the US-ASCII code range. A fallback position.
Works with any JDK, any encoding.
Simple example how to use it:
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.bind.marshaller.DumbEscapeHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.io.PrintWriter;
public class JaxbApp
public static void main(String[] args) throws Exception
FreeTextNode dataFile = new FreeTextNode();
dataFile.setValue("hello i have < b > bold < / b > text inside.");
JAXBContext jaxbContext = JAXBContext.newInstance(FreeTextNode.class);
Marshaller marshaller = jaxbContext.createMarshaller();
PrintWriter printWriter = new PrintWriter(System.out);
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(dataFile, dataWriter);
@XmlRootElement(name = "freetextnode")
class FreeTextNode
private String value;
@XmlValue
public String getValue()
return value;
public void setValue(String value)
this.value = value;
Above code prints:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<freetextnode>hello i have < b > bold < / b > text inside.</freetextnode>
See also:
- Can I force JAXB not to convert " into ", for example, when marshalling to XML?
- DumbEscapeHandler
answered yesterday
Michał ZioberMichał Ziober
16.6k1269108
16.6k1269108
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
add a comment |
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
A bit too much, since I only need a solution for >, but great solution.
– PdM
12 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280620%2fjava-jaxb-marshaller-changes-encoding-of-but-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What is your question? The
>
does not need to be escaped since it does not signal anything special to the lexer/parser. If you really need to escape it, do it manually.– f1sh
yesterday
@f1sh that's true. but is there i simple option (not rewriting marshaller/beforeMarshaller/afterMarshaller) to do this during marshalling?
– PdM
yesterday